From: Sebastian Harl Date: Mon, 16 Jun 2014 06:35:19 +0000 (+0200) Subject: grammar: Simplified compare matcher parser. X-Git-Tag: sysdb-0.2.0~58 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f2be3352d0658d429733b8d5adbc3c5e7b50089a;p=sysdb.git grammar: Simplified compare matcher parser. --- diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index abab594..75885c5 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -66,6 +66,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %name-prefix "sdb_fe_yy" %union { + const char *sstr; /* static string */ char *str; sdb_llist_t *list; @@ -104,6 +105,8 @@ 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($$)); } @@ -287,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 { $$ = "!~"; } ; %%