diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index c4c47755caa9b2c032ff0593b2a2134130a2c607..e0d8e7ecc46136b01cb84546ba1d3e11d7fb9e2b 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 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
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 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:
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; }
;
%%