X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fgrammar.y;h=50bb00e7f632fa35abb283ca7025b0c02a80a908;hb=8f340af6edef3f5a7f6b5e13ff960ade8abc3f24;hp=004a5effa1537a29473066103757cd169867c37a;hpb=9ae83505d8025ab32a8bdf7904ff4df8f9e661bf;p=sysdb.git diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 004a5ef..50bb00e 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -75,13 +75,16 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %token SCANNER_ERROR -%token IDENTIFIER -%token FETCH LIST +%token WHERE + +%token IDENTIFIER STRING +%token FETCH LIST LOOKUP %type statements %type statement fetch_statement list_statement + lookup_statement expression %% @@ -141,22 +144,36 @@ statement: | list_statement | + lookup_statement + | /* empty */ { $$ = NULL; } ; +/* + * FETCH ; + * + * Retrieve detailed information about a single host. + */ fetch_statement: - FETCH IDENTIFIER + FETCH STRING { $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_fetch_t, conn_fetch_destroy)); CONN_FETCH($$)->name = strdup($2); $$->cmd = CONNECTION_FETCH; + free($2); + $2 = NULL; } ; +/* + * LIST; + * + * Returns a list of all hosts in the store. + */ list_statement: LIST { @@ -166,8 +183,34 @@ list_statement: } ; +/* + * LOOKUP WHERE ; + * + * Returns detailed information about matching expression. + */ +lookup_statement: + LOOKUP IDENTIFIER WHERE expression + { + /* TODO: support other types as well */ + if (strcasecmp($2, "hosts")) { + char errmsg[strlen($2) + 32]; + snprintf(errmsg, sizeof(errmsg), + YY_("unknown table %s"), $2); + sdb_fe_yyerror(&yylloc, scanner, errmsg); + YYABORT; + } + + $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, + conn_lookup_t, conn_lookup_destroy)); + CONN_LOOKUP($$)->matcher = CONN_MATCHER($4); + $$->cmd = CONNECTION_LOOKUP; + free($2); + $2 = NULL; + } + ; + expression: - IDENTIFIER + STRING { $$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL, conn_node_matcher_t));