Code

frontend: Actually implement support for the NOT operator.
authorSebastian Harl <sh@tokkee.org>
Sun, 6 Apr 2014 17:57:07 +0000 (19:57 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 6 Apr 2014 17:57:07 +0000 (19:57 +0200)
src/frontend/grammar.y
src/frontend/scanner.l
t/frontend/parser_test.c

index 858c766b698aa124308a292f8ddcf90250127120..1cf068538bc13f7686fc12df2d0ba22247f9d553 100644 (file)
@@ -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,
index 32c13c54c355865d4024e94f683a06b6330b9492..dd2a86cf5273b4e5e3c450c02306820b282a1a46 100644 (file)
@@ -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"))
index ffeca8f68b091d50e5c90c5d165edf2867986b1f..74075b3a6c8de866840891e52d975fdc0fdc35ba 100644 (file)
@@ -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 },