X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fgrammar.y;h=8e5ddf6e5eff7a1e32646ad0d62795109a2b61f9;hb=c08c6541795e2ca4da72640a449347d7b708b1dc;hp=a261c4c81d3253320b9d8cf960378918f84d0249;hpb=72a63cfb0e65bb575889b8dbee6648cafd6a52f2;p=sysdb.git diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index a261c4c..8e5ddf6 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -63,9 +63,10 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %locations %error-verbose %expect 0 -%name-prefix="sdb_fe_yy" +%name-prefix "sdb_fe_yy" %union { + const char *sstr; /* static string */ char *str; sdb_llist_t *list; @@ -79,11 +80,11 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %token SCANNER_ERROR %token AND OR NOT WHERE - %token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX +%token FETCH LIST LOOKUP + %token IDENTIFIER STRING -%token FETCH LIST LOOKUP /* Precedence (lowest first): */ %left OR @@ -104,6 +105,11 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %type matcher compare_matcher +%type op + +%destructor { free($$); } +%destructor { sdb_object_deref(SDB_OBJ($$)); } + %% statements: @@ -255,16 +261,21 @@ matcher: matcher AND matcher { $$ = sdb_store_con_matcher($1, $3); + sdb_object_deref(SDB_OBJ($1)); + sdb_object_deref(SDB_OBJ($3)); } | matcher OR matcher { $$ = sdb_store_dis_matcher($1, $3); + sdb_object_deref(SDB_OBJ($1)); + sdb_object_deref(SDB_OBJ($3)); } | NOT matcher { $$ = sdb_store_inv_matcher($2); + sdb_object_deref(SDB_OBJ($2)); } | compare_matcher @@ -279,39 +290,23 @@ matcher: * Parse matchers comparing object attributes with a value. */ compare_matcher: - IDENTIFIER '.' IDENTIFIER CMP_EQUAL STRING + IDENTIFIER '.' IDENTIFIER op STRING { - $$ = sdb_store_matcher_parse_cmp($1, $3, "=", $5); - /* TODO: simplify memory management in the parser */ + $$ = sdb_store_matcher_parse_cmp($1, $3, $4, $5); free($1); $1 = NULL; free($3); $3 = NULL; free($5); $5 = NULL; } + ; + +op: + CMP_EQUAL { $$ = "="; } | - IDENTIFIER '.' IDENTIFIER CMP_NEQUAL STRING - { - $$ = sdb_store_matcher_parse_cmp($1, $3, "!=", $5); - /* TODO: simplify memory management in the parser */ - free($1); $1 = NULL; - free($3); $3 = NULL; - free($5); $5 = NULL; - } + CMP_NEQUAL { $$ = "!="; } | - IDENTIFIER '.' IDENTIFIER CMP_REGEX STRING - { - $$ = sdb_store_matcher_parse_cmp($1, $3, "=~", $5); - free($1); $1 = NULL; - free($3); $3 = NULL; - free($5); $5 = NULL; - } + CMP_REGEX { $$ = "=~"; } | - IDENTIFIER '.' IDENTIFIER CMP_NREGEX STRING - { - $$ = sdb_store_matcher_parse_cmp($1, $3, "!~", $5); - free($1); $1 = NULL; - free($3); $3 = NULL; - free($5); $5 = NULL; - } + CMP_NREGEX { $$ = "!~"; } ; %%