diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index c2440e8a16a585b8dcbf5b441cb42bc57e48765b..402e17087f692744f2dea73068654daced1d1134 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%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;
%type <m> matcher
compare_matcher
+%type <sstr> op
+
+%destructor { free($$); } <str>
+%destructor { sdb_object_deref(SDB_OBJ($$)); } <node> <m>
+
%%
statements:
* 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_data_t data = { SDB_TYPE_STRING, { .string = $5 } };
+ $$ = sdb_store_matcher_parse_cmp($1, $3, $4, &data);
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 { $$ = "!~"; }
;
%%
-/* XXX: on parse errors, allocated objects, strings, etc. need to be freed */
-
void
sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg)
{