From 06622be23c09a9ca3d44d476139f0bf204aa4ec6 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 6 Apr 2014 19:57:07 +0200 Subject: [PATCH] frontend: Actually implement support for the NOT operator. --- src/frontend/grammar.y | 3 ++- src/frontend/scanner.l | 2 ++ t/frontend/parser_test.c | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 858c766..1cf0685 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -246,7 +246,8 @@ expression: if ((M(m)->type == MATCHER_HOST) || (M(m)->type == MATCHER_AND) - || (M(m)->type == MATCHER_OR)) + || (M(m)->type == MATCHER_OR) + || (M(m)->type == MATCHER_NOT)) CONN_MATCHER($$)->matcher = m; else if (M(m)->type == MATCHER_SERVICE) CONN_MATCHER($$)->matcher = sdb_store_host_matcher(NULL, diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l index 32c13c5..dd2a86c 100644 --- a/src/frontend/scanner.l +++ b/src/frontend/scanner.l @@ -100,6 +100,8 @@ string ('[^']*') return LIST; else if (! strcasecmp(yytext, "LOOKUP")) return LOOKUP; + else if (! strcasecmp(yytext, "NOT")) + return NOT; else if (! strcasecmp(yytext, "OR")) return OR; else if (! strcasecmp(yytext, "WHERE")) diff --git a/t/frontend/parser_test.c b/t/frontend/parser_test.c index ffeca8f..74075b3 100644 --- a/t/frontend/parser_test.c +++ b/t/frontend/parser_test.c @@ -60,13 +60,22 @@ START_TEST(test_parse) { "LOOKUP hosts WHERE " "host.name = 'host'", -1, 1, CONNECTION_LOOKUP }, + { "LOOKUP hosts WHERE NOT " + "host.name = 'host'", -1, 1, CONNECTION_LOOKUP }, { "LOOKUP hosts WHERE " "host.name =~ 'p' AND " "service.name =~ 'p'", -1, 1, CONNECTION_LOOKUP }, + { "LOOKUP hosts WHERE NOT " + "host.name =~ 'p' AND " + "service.name =~ 'p'", -1, 1, CONNECTION_LOOKUP }, { "LOOKUP hosts WHERE " "host.name =~ 'p' AND " "service.name =~ 'p' OR " "service.name =~ 'r'", -1, 1, CONNECTION_LOOKUP }, + { "LOOKUP hosts WHERE NOT " + "host.name =~ 'p' AND " + "service.name =~ 'p' OR " + "service.name =~ 'r'", -1, 1, CONNECTION_LOOKUP }, /* comments */ { "/* some comment */", -1, 0, 0 }, @@ -139,6 +148,7 @@ START_TEST(test_parse_matcher) "service.name =~ 'pattern'", -1, MATCHER_AND }, { "host.name =~ 'pattern' OR " "service.name =~ 'pattern'", -1, MATCHER_OR }, + { "NOT host.name = 'host'", -1, MATCHER_NOT }, /* check operator precedence */ { "host.name = 'name' OR " @@ -157,6 +167,12 @@ START_TEST(test_parse_matcher) "service.name = 'name') AND " "(attribute.name = 'name' OR " "attribute.foo = 'bar')", -1, MATCHER_AND }, + { "NOT host.name = 'name' OR " + "service.name = 'name'", -1, MATCHER_OR }, + { "NOT host.name = 'name' OR " + "NOT service.name = 'name'", -1, MATCHER_OR }, + { "NOT (host.name = 'name' OR " + "NOT service.name = 'name')", -1, MATCHER_NOT }, /* syntax errors */ { "LIST", -1, -1 }, -- 2.30.2