Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / frontend / grammar.y
index c4c47755caa9b2c032ff0593b2a2134130a2c607..e0d8e7ecc46136b01cb84546ba1d3e11d7fb9e2b 100644 (file)
@@ -81,19 +81,27 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
 %token SCANNER_ERROR
 
-%token AND OR NOT WHERE
+%token AND OR IS NOT MATCHING
 %token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
+%token CMP_LT CMP_LE CMP_GE CMP_GT
+
+/* NULL token */
+%token NULL_T
 
 %token FETCH LIST LOOKUP
 
 %token <str> IDENTIFIER STRING
 
+%token <data> INTEGER FLOAT
+
 /* Precedence (lowest first): */
 %left OR
 %left AND
-%left NOT
+%right NOT
 %left CMP_EQUAL CMP_NEQUAL
-%left CMP_REGEX CMP_NREGEX
+%left CMP_LT CMP_LE CMP_GE CMP_GT
+%nonassoc CMP_REGEX CMP_NREGEX
+%nonassoc IS
 %left '(' ')'
 %left '.'
 
@@ -102,7 +110,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
        fetch_statement
        list_statement
        lookup_statement
-       expression
+       condition
 
 %type <m> matcher
        compare_matcher
@@ -123,7 +131,7 @@ statements:
                        if (parser_mode != SDB_PARSE_DEFAULT) {
                                sdb_fe_yyerror(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
-                                                       "expecting expression"));
+                                                       "expecting condition"));
                                sdb_object_deref(SDB_OBJ($3));
                                YYABORT;
                        }
@@ -140,7 +148,7 @@ statements:
                        if (parser_mode != SDB_PARSE_DEFAULT) {
                                sdb_fe_yyerror(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
-                                                       "expecting expression"));
+                                                       "expecting condition"));
                                sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
@@ -151,12 +159,12 @@ statements:
                        }
                }
        |
-       expression
+       condition
                {
-                       /* only accept this in expression parse mode */
-                       if (! (parser_mode & SDB_PARSE_EXPR)) {
+                       /* only accept this in condition parse mode */
+                       if (! (parser_mode & SDB_PARSE_COND)) {
                                sdb_fe_yyerror(&yylloc, scanner,
-                                               YY_("syntax error, unexpected expression, "
+                                               YY_("syntax error, unexpected condition, "
                                                        "expecting statement"));
                                sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
@@ -213,12 +221,12 @@ list_statement:
        ;
 
 /*
- * LOOKUP <type> WHERE <expression>;
+ * LOOKUP <type> MATCHING <condition>;
  *
- * Returns detailed information about <type> matching expression.
+ * Returns detailed information about <type> matching condition.
  */
 lookup_statement:
-       LOOKUP IDENTIFIER WHERE expression
+       LOOKUP IDENTIFIER MATCHING condition
                {
                        /* TODO: support other types as well */
                        if (strcasecmp($2, "hosts")) {
@@ -239,13 +247,13 @@ lookup_statement:
                }
        ;
 
-expression:
+condition:
        matcher
                {
                        if (! $1) {
                                /* TODO: improve error reporting */
                                sdb_fe_yyerror(&yylloc, scanner,
-                                               YY_("syntax error, invalid expression"));
+                                               YY_("syntax error, invalid condition"));
                                YYABORT;
                        }
 
@@ -294,6 +302,13 @@ matcher:
  * Parse matchers comparing object attributes with a value.
  */
 compare_matcher:
+       IDENTIFIER op data
+               {
+                       $$ = sdb_store_matcher_parse_cmp($1, NULL, $2, &$3);
+                       free($1); $1 = NULL;
+                       sdb_data_free_datum(&$3);
+               }
+       |
        IDENTIFIER '.' IDENTIFIER op data
                {
                        $$ = sdb_store_matcher_parse_cmp($1, $3, $4, &$5);
@@ -301,6 +316,25 @@ compare_matcher:
                        free($3); $3 = NULL;
                        sdb_data_free_datum(&$5);
                }
+       |
+       IDENTIFIER '.' IDENTIFIER IS NULL_T
+               {
+                       $$ = sdb_store_matcher_parse_cmp($1, $3, "IS", NULL);
+                       free($1); $1 = NULL;
+                       free($3); $3 = NULL;
+               }
+       |
+       IDENTIFIER '.' IDENTIFIER IS NOT NULL_T
+               {
+                       sdb_store_matcher_t *m;
+                       m = sdb_store_matcher_parse_cmp($1, $3, "IS", NULL);
+                       free($1); $1 = NULL;
+                       free($3); $3 = NULL;
+
+                       /* sdb_store_inv_matcher return NULL if m==NULL */
+                       $$ = sdb_store_inv_matcher(m);
+                       sdb_object_deref(SDB_OBJ(m));
+               }
        ;
 
 op:
@@ -311,10 +345,22 @@ op:
        CMP_REGEX { $$ = "=~"; }
        |
        CMP_NREGEX { $$ = "!~"; }
+       |
+       CMP_LT { $$ = "<"; }
+       |
+       CMP_LE { $$ = "<="; }
+       |
+       CMP_GE { $$ = ">="; }
+       |
+       CMP_GT { $$ = ">"; }
        ;
 
 data:
        STRING { $$.type = SDB_TYPE_STRING; $$.data.string = $1; }
+       |
+       INTEGER { $$ = $1; }
+       |
+       FLOAT { $$ = $1; }
        ;
 
 %%