diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index a607ee0aba96bd0698147b81e0d441ab55182451..ed4de830fc64cc0f091a52c43624fd325ee96e17 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
sdb_conn_node_t *node;
sdb_store_matcher_t *m;
sdb_conn_node_t *node;
sdb_store_matcher_t *m;
+ sdb_store_expr_t *expr;
}
%start statements
%token SCANNER_ERROR
}
%start statements
%token SCANNER_ERROR
-%token AND OR IS 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
%token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
%token CMP_LT CMP_LE CMP_GE CMP_GT
+%token CONCAT
/* NULL token */
%token NULL_T
/* NULL token */
%token NULL_T
%left CMP_EQUAL CMP_NEQUAL
%left CMP_LT CMP_LE CMP_GE CMP_GT
%nonassoc CMP_REGEX CMP_NREGEX
%left CMP_EQUAL CMP_NEQUAL
%left CMP_LT CMP_LE CMP_GE CMP_GT
%nonassoc CMP_REGEX CMP_NREGEX
+%left CONCAT
%nonassoc IS
%nonassoc IS
+%left '+' '-'
+%left '*' '/' '%'
%left '(' ')'
%left '.'
%left '(' ')'
%left '.'
%type <m> matcher
compare_matcher
%type <m> matcher
compare_matcher
+%type <expr> expression
+
%type <sstr> op
%type <data> data
%destructor { free($$); } <str>
%type <sstr> op
%type <data> data
%destructor { free($$); } <str>
-%destructor { sdb_object_deref(SDB_OBJ($$)); } <node> <m>
+%destructor { sdb_object_deref(SDB_OBJ($$)); } <node> <m> <expr>
%%
%%
;
/*
;
/*
- * LOOKUP <type> WHERE <condition>;
+ * LOOKUP <type> MATCHING <condition>;
*
* Returns detailed information about <type> matching condition.
*/
lookup_statement:
*
* Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP IDENTIFIER WHERE condition
+ LOOKUP IDENTIFIER MATCHING condition
{
/* TODO: support other types as well */
if (strcasecmp($2, "hosts")) {
{
/* TODO: support other types as well */
if (strcasecmp($2, "hosts")) {
* Parse matchers comparing object attributes with a value.
*/
compare_matcher:
* Parse matchers comparing object attributes with a value.
*/
compare_matcher:
- IDENTIFIER op data
+ IDENTIFIER op expression
{
{
- $$ = sdb_store_matcher_parse_cmp($1, NULL, $2, &$3);
+ $$ = sdb_store_matcher_parse_cmp($1, NULL, $2, $3);
free($1); $1 = NULL;
free($1); $1 = NULL;
- sdb_data_free_datum(&$3);
+ sdb_object_deref(SDB_OBJ($3));
}
|
}
|
- IDENTIFIER '.' IDENTIFIER op data
+ IDENTIFIER '.' IDENTIFIER op expression
{
{
- $$ = sdb_store_matcher_parse_cmp($1, $3, $4, &$5);
+ $$ = sdb_store_matcher_parse_cmp($1, $3, $4, $5);
free($1); $1 = NULL;
free($3); $3 = NULL;
free($1); $1 = NULL;
free($3); $3 = NULL;
- sdb_data_free_datum(&$5);
+ sdb_object_deref(SDB_OBJ($5));
}
|
IDENTIFIER '.' IDENTIFIER IS NULL_T
}
|
IDENTIFIER '.' IDENTIFIER IS NULL_T
}
;
}
;
+expression:
+ '(' expression ')'
+ {
+ $$ = $2;
+ }
+ |
+ expression '+' expression
+ {
+ $$ = sdb_store_expr_create(SDB_DATA_ADD, $1, $3);
+ sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
+ sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
+ }
+ |
+ expression '-' expression
+ {
+ $$ = sdb_store_expr_create(SDB_DATA_SUB, $1, $3);
+ sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
+ sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
+ }
+ |
+ expression '*' expression
+ {
+ $$ = sdb_store_expr_create(SDB_DATA_MUL, $1, $3);
+ sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
+ sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
+ }
+ |
+ expression '/' expression
+ {
+ $$ = sdb_store_expr_create(SDB_DATA_DIV, $1, $3);
+ sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
+ sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
+ }
+ |
+ expression '%' expression
+ {
+ $$ = sdb_store_expr_create(SDB_DATA_MOD, $1, $3);
+ sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
+ sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
+ }
+ |
+ data
+ {
+ $$ = sdb_store_expr_constvalue(&$1);
+ sdb_data_free_datum(&$1);
+ }
+ ;
+
op:
CMP_EQUAL { $$ = "="; }
|
op:
CMP_EQUAL { $$ = "="; }
|