diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 34a9c6b6474502d9fc059df45a6ed93a79890567..a607ee0aba96bd0698147b81e0d441ab55182451 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%token SCANNER_ERROR
-%token AND OR NOT WHERE
+%token AND OR IS NOT WHERE
%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
%right NOT
%left CMP_EQUAL CMP_NEQUAL
%left CMP_LT CMP_LE CMP_GE CMP_GT
-%left CMP_REGEX CMP_NREGEX
+%nonassoc CMP_REGEX CMP_NREGEX
+%nonassoc IS
%left '(' ')'
%left '.'
fetch_statement
list_statement
lookup_statement
- expression
+ condition
%type <m> matcher
compare_matcher
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> WHERE <condition>;
*
- * Returns detailed information about <type> matching expression.
+ * Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP IDENTIFIER WHERE expression
+ LOOKUP IDENTIFIER WHERE 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 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($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_t *m;
+ m = sdb_store_matcher_parse_cmp($1, $3, "IS", NULL);
+ free($1); $1 = NULL;
+ free($3); $3 = NULL;
+
+ /* sdb_store_inv_matcher return NULL if m==NULL */
+ $$ = sdb_store_inv_matcher(m);
+ sdb_object_deref(SDB_OBJ(m));
+ }
;
op: