diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 75885c5259960433675b38f47a0bd90b857acff9..e0d8e7ecc46136b01cb84546ba1d3e11d7fb9e2b 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
const char *sstr; /* static string */
char *str;
+ sdb_data_t data;
+
sdb_llist_t *list;
sdb_conn_node_t *node;
%token SCANNER_ERROR
-%token AND OR NOT WHERE
+%token AND OR IS NOT MATCHING
%token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
+%token CMP_LT CMP_LE CMP_GE CMP_GT
+
+/* NULL token */
+%token NULL_T
%token FETCH LIST LOOKUP
%token <str> IDENTIFIER STRING
+%token <data> INTEGER FLOAT
+
/* Precedence (lowest first): */
%left OR
%left AND
-%left NOT
+%right NOT
%left CMP_EQUAL CMP_NEQUAL
-%left CMP_REGEX CMP_NREGEX
+%left CMP_LT CMP_LE CMP_GE CMP_GT
+%nonassoc CMP_REGEX CMP_NREGEX
+%nonassoc IS
%left '(' ')'
%left '.'
fetch_statement
list_statement
lookup_statement
- expression
+ condition
%type <m> matcher
compare_matcher
%type <sstr> op
+%type <data> data
+
%destructor { free($$); } <str>
%destructor { sdb_object_deref(SDB_OBJ($$)); } <node> <m>
if (parser_mode != SDB_PARSE_DEFAULT) {
sdb_fe_yyerror(&yylloc, scanner,
YY_("syntax error, unexpected statement, "
- "expecting expression"));
+ "expecting condition"));
sdb_object_deref(SDB_OBJ($3));
YYABORT;
}
if (parser_mode != SDB_PARSE_DEFAULT) {
sdb_fe_yyerror(&yylloc, scanner,
YY_("syntax error, unexpected statement, "
- "expecting expression"));
+ "expecting condition"));
sdb_object_deref(SDB_OBJ($1));
YYABORT;
}
}
}
|
- expression
+ condition
{
- /* only accept this in expression parse mode */
- if (! (parser_mode & SDB_PARSE_EXPR)) {
+ /* only accept this in condition parse mode */
+ if (! (parser_mode & SDB_PARSE_COND)) {
sdb_fe_yyerror(&yylloc, scanner,
- YY_("syntax error, unexpected expression, "
+ YY_("syntax error, unexpected condition, "
"expecting statement"));
sdb_object_deref(SDB_OBJ($1));
YYABORT;
;
/*
- * LOOKUP <type> WHERE <expression>;
+ * LOOKUP <type> MATCHING <condition>;
*
- * Returns detailed information about <type> matching expression.
+ * Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP IDENTIFIER WHERE expression
+ LOOKUP IDENTIFIER MATCHING condition
{
/* TODO: support other types as well */
if (strcasecmp($2, "hosts")) {
}
;
-expression:
+condition:
matcher
{
if (! $1) {
/* TODO: improve error reporting */
sdb_fe_yyerror(&yylloc, scanner,
- YY_("syntax error, invalid expression"));
+ YY_("syntax error, invalid condition"));
YYABORT;
}
* Parse matchers comparing object attributes with a value.
*/
compare_matcher:
- IDENTIFIER '.' IDENTIFIER op STRING
+ IDENTIFIER op data
+ {
+ $$ = sdb_store_matcher_parse_cmp($1, NULL, $2, &$3);
+ free($1); $1 = NULL;
+ sdb_data_free_datum(&$3);
+ }
+ |
+ IDENTIFIER '.' IDENTIFIER op data
+ {
+ $$ = sdb_store_matcher_parse_cmp($1, $3, $4, &$5);
+ free($1); $1 = NULL;
+ free($3); $3 = NULL;
+ sdb_data_free_datum(&$5);
+ }
+ |
+ 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
{
- $$ = sdb_store_matcher_parse_cmp($1, $3, $4, $5);
+ sdb_store_matcher_t *m;
+ m = sdb_store_matcher_parse_cmp($1, $3, "IS", NULL);
free($1); $1 = NULL;
free($3); $3 = NULL;
- free($5); $5 = NULL;
+
+ /* sdb_store_inv_matcher return NULL if m==NULL */
+ $$ = sdb_store_inv_matcher(m);
+ sdb_object_deref(SDB_OBJ(m));
}
;
CMP_REGEX { $$ = "=~"; }
|
CMP_NREGEX { $$ = "!~"; }
+ |
+ CMP_LT { $$ = "<"; }
+ |
+ CMP_LE { $$ = "<="; }
+ |
+ CMP_GE { $$ = ">="; }
+ |
+ CMP_GT { $$ = ">"; }
;
-%%
+data:
+ STRING { $$.type = SDB_TYPE_STRING; $$.data.string = $1; }
+ |
+ INTEGER { $$ = $1; }
+ |
+ FLOAT { $$ = $1; }
+ ;
-/* 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)