Code

frontend/grammar: Use '.' instead of ':' to access queryable object fields.
[sysdb.git] / src / frontend / grammar.y
index 58363df01dbebe37b861394f09632d47397b850a..9cf98eef406c2b5ecb54096706fd4abba8849050 100644 (file)
@@ -113,6 +113,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 %nonassoc IS
 %left '+' '-'
 %left '*' '/' '%'
+%left '[' ']'
 %left '(' ')'
 %left '.'
 
@@ -234,6 +235,7 @@ fetch_statement:
 
                        $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
                                                conn_fetch_t, conn_fetch_destroy));
+                       CONN_FETCH($$)->type = SDB_HOST;
                        CONN_FETCH($$)->name = $3;
                        CONN_FETCH($$)->filter = CONN_MATCHER($4);
                        $$->cmd = CONNECTION_FETCH;
@@ -249,8 +251,8 @@ fetch_statement:
 list_statement:
        LIST IDENTIFIER filter_clause
                {
-                       /* TODO: support other types as well */
-                       if (strcasecmp($2, "hosts")) {
+                       int type = sdb_store_parse_object_type_plural($2);
+                       if (type < 0) {
                                char errmsg[strlen($2) + 32];
                                snprintf(errmsg, sizeof(errmsg),
                                                YY_("unknown data-source %s"), $2);
@@ -262,6 +264,7 @@ list_statement:
 
                        $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
                                                conn_list_t, conn_list_destroy));
+                       CONN_LIST($$)->type = type;
                        CONN_LIST($$)->filter = CONN_MATCHER($3);
                        $$->cmd = CONNECTION_LIST;
                        free($2); $2 = NULL;
@@ -290,6 +293,7 @@ lookup_statement:
 
                        $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
                                                conn_lookup_t, conn_lookup_destroy));
+                       CONN_LOOKUP($$)->type = SDB_HOST;
                        CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
                        CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
                        $$->cmd = CONNECTION_LOOKUP;
@@ -394,7 +398,7 @@ matcher:
  * Parse matchers comparing object attributes with a value.
  */
 compare_matcher:
-       ':' IDENTIFIER op expression
+       '.' IDENTIFIER op expression
                {
                        $$ = sdb_store_matcher_parse_field_cmp($2, $3, $4);
                        free($2); $2 = NULL;
@@ -408,22 +412,22 @@ compare_matcher:
                        sdb_object_deref(SDB_OBJ($3));
                }
        |
-       IDENTIFIER '.' IDENTIFIER op expression
+       IDENTIFIER '[' IDENTIFIER ']' op expression
                {
-                       $$ = sdb_store_matcher_parse_cmp($1, $3, $4, $5);
+                       $$ = sdb_store_matcher_parse_cmp($1, $3, $5, $6);
                        free($1); $1 = NULL;
                        free($3); $3 = NULL;
-                       sdb_object_deref(SDB_OBJ($5));
+                       sdb_object_deref(SDB_OBJ($6));
                }
        |
-       IDENTIFIER '.' IDENTIFIER IS NULL_T
+       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
+       IDENTIFIER '[' IDENTIFIER ']' IS NOT NULL_T
                {
                        sdb_store_matcher_t *m;
                        m = sdb_store_matcher_parse_cmp($1, $3, "IS", NULL);
@@ -477,7 +481,7 @@ expression:
                        sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
                }
        |
-       ':' IDENTIFIER
+       '.' IDENTIFIER
                {
                        int field = sdb_store_parse_field_name($2);
                        free($2); $2 = NULL;