Add emacs/vim local variables
[yaz-moved-to-github.git] / src / cql.y
index 2670216..00d806a 100644 (file)
--- a/src/cql.y
+++ b/src/cql.y
@@ -1,13 +1,8 @@
-/* $Id: cql.y,v 1.17 2008-01-06 16:22:02 adam Exp $
-   Copyright (C) 2002-2006
-   Index Data ApS
-
-This file is part of the YAZ toolkit.
-
-See the file LICENSE.
-
- bison parser for CQL grammar.
-*/
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2011 Index Data
+ * See the file LICENSE for details.
+ */ 
+/* bison parser for CQL grammar. */
 %{
 /** 
  * \file cql.c
@@ -16,10 +11,13 @@ See the file LICENSE.
  * This is a YACC parser, but since it must be reentrant, Bison is required.
  * The original source file is cql.y.
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
+#include <yaz/yaz-iconv.h>
 #include <yaz/xmalloc.h>
 #include <yaz/nmem.h>
 #include <yaz/cql.h>
@@ -58,7 +56,7 @@ See the file LICENSE.
 %}
 
 %pure_parser
-%token DOTTERM TERM AND OR NOT PROX GE LE NE EXACT
+%token DOTTERM TERM AND OR NOT PROX GE LE NE EXACT SORTBY
 
 %%
 
@@ -66,12 +64,20 @@ top: {
     $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem,
                            "cql.serverChoice", "=", 0);
     ((CQL_parser) parm)->top = 0;
-} cqlQuery1 {
+} cqlQuery1 sortby {
     cql_node_destroy($$.rel);
     ((CQL_parser) parm)->top = $2.cql; 
 }
 ;
 
+sortby: /* empty */
+| SORTBY sortSpec;
+
+sortSpec: sortSpec singleSpec
+| singleSpec; 
+
+singleSpec: index modifiers ;
+
 cqlQuery1: cqlQuery
 | cqlQuery error {
     cql_node_destroy($1.cql);
@@ -208,6 +214,7 @@ searchTerm:
 | OR
 | NOT
 | PROX
+| SORTBY
 ;
 
 %%
@@ -259,7 +266,7 @@ int yylex(YYSTYPE *lval, void *vp)
             return 0;
         if (c == '\n')
             return 0;
-    } while (isspace(c));
+    } while (yaz_isspace(c));
     if (strchr("()=></", c))
     {
         int c1;
@@ -363,6 +370,11 @@ int yylex(YYSTYPE *lval, void *vp)
            lval->buf = "prox";
            return PROX;
        }
+       if (!cql_strcmp(lval->buf, "sortby"))
+       {
+           lval->buf = "sortby";
+           return SORTBY;
+       }
        if (!cql_strcmp(lval->buf, "all"))
            relation_like = 1;
        if (!cql_strcmp(lval->buf, "any"))
@@ -416,3 +428,11 @@ struct cql_node *cql_parser_result(CQL_parser cp)
 {
     return cp->top;
 }
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */