From: Sebastian Harl Date: Thu, 23 Oct 2014 19:30:00 +0000 (+0200) Subject: frontend/grammar: Implement ' ' using new-style matchers. X-Git-Tag: sysdb-0.6.0~68 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=f89dd3ecd32868138cfb76b7f52e26615e54e297 frontend/grammar: Implement ' ' using new-style matchers. --- diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 435b247..3c813dc 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -445,9 +445,26 @@ compare_matcher: | IDENTIFIER cmp expression { - $$ = sdb_store_matcher_parse_cmp($1, $2, $3); + int type = sdb_store_parse_object_type($1); + sdb_store_expr_t *e = sdb_store_expr_fieldvalue(SDB_FIELD_NAME); + sdb_store_matcher_op_cb cb = sdb_store_parse_matcher_op($2); + sdb_store_matcher_t *m; + assert(cb); + + m = cb(e, $3); + /* TODO: this only works as long as queries + * are limited to hosts */ + if (type == SDB_HOST) { + $$ = m; + } + else { + $$ = sdb_store_child_matcher(type, m); + sdb_object_deref(SDB_OBJ(m)); + } + free($1); $1 = NULL; sdb_object_deref(SDB_OBJ($3)); + sdb_object_deref(SDB_OBJ(e)); } | expression IS NULL_T diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index e251d71..6b9e86e 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -306,22 +306,27 @@ START_TEST(test_parse_matcher) { "", -1, -1 }, /* valid expressions */ - { "host = 'localhost'", -1, MATCHER_NAME }, - { "host != 'localhost'", -1, MATCHER_NOT }, - { "host =~ 'host'", -1, MATCHER_NAME }, - { "host !~ 'host'", -1, MATCHER_NOT }, - { "host = 'localhost' -- foo", -1, MATCHER_NAME }, - { "host = 'host' ", 13, MATCHER_NAME }, + { "host = 'localhost'", -1, MATCHER_EQ }, + { "host != 'localhost'", -1, MATCHER_NE }, + { "host =~ 'host'", -1, MATCHER_REGEX }, + { "host !~ 'host'", -1, MATCHER_NREGEX }, + { "host = 'localhost' -- foo", -1, MATCHER_EQ }, + { "host = 'host' ", 13, MATCHER_EQ }, /* match hosts by service */ - { "service = 'name'", -1, MATCHER_NAME }, - { "service != 'name'", -1, MATCHER_NOT }, - { "service =~ 'pattern'", -1, MATCHER_NAME }, - { "service !~ 'pattern'", -1, MATCHER_NOT }, + { "service = 'name'", -1, MATCHER_SERVICE }, + { "service != 'name'", -1, MATCHER_SERVICE }, + { "service =~ 'pattern'", -1, MATCHER_SERVICE }, + { "service !~ 'pattern'", -1, MATCHER_SERVICE }, + /* match hosts by metric */ + { "metric = 'name'", -1, MATCHER_METRIC }, + { "metric != 'name'", -1, MATCHER_METRIC }, + { "metric =~ 'pattern'", -1, MATCHER_METRIC }, + { "metric !~ 'pattern'", -1, MATCHER_METRIC }, /* match hosts by attribute */ - { "attribute = 'name'", -1, MATCHER_NAME }, - { "attribute != 'name'", -1, MATCHER_NOT }, - { "attribute =~ 'pattern'", -1, MATCHER_NAME }, - { "attribute !~ 'pattern'", -1, MATCHER_NOT }, + { "attribute = 'name'", -1, MATCHER_ATTRIBUTE }, + { "attribute != 'name'", -1, MATCHER_ATTRIBUTE }, + { "attribute =~ 'pattern'", -1, MATCHER_ATTRIBUTE }, + { "attribute !~ 'pattern'", -1, MATCHER_ATTRIBUTE }, /* composite expressions */ { "host =~ 'pattern' AND " "service =~ 'pattern'", -1, MATCHER_AND },