lexer, parser, matcher: extend grammar to allow comma separated keys/indexes as more...
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 1 Jan 2014 21:38:08 +0000 (21:38 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 1 Jan 2014 21:53:06 +0000 (21:53 +0000)
lexer.l
matcher.c
parser.y

diff --git a/lexer.l b/lexer.l
index 18937e888355774c04e7d7883d8a017b19ad08a5..d1844a296e46978681845cb1658e12e4c0a01183 100644 (file)
--- a/lexer.l
+++ b/lexer.l
@@ -77,6 +77,7 @@ BROPEN                "["
 BRCLOSE                "]"
 POPEN          "("
 PCLOSE         ")"
+COMMA          ","
 
 ROOT           "$"
 THIS           "@"
@@ -160,6 +161,7 @@ WS                  [ \t\n]*
 {BRCLOSE}      { return T_BRCLOSE; }
 {POPEN}                { return T_POPEN; }
 {PCLOSE}       { return T_PCLOSE; }
+{COMMA}                { return T_UNION; }
 
 {ROOT}         { return T_ROOT; }
 {THIS}         { return T_THIS; }
index 9d2aa89e878ea715732a66e3f7a94c3b375c60ff..51e0e3c700002318067d714f253f1bee7cc134fc 100644 (file)
--- a/matcher.c
+++ b/matcher.c
@@ -164,6 +164,7 @@ jp_expr(struct jp_opcode *op, struct json_object *root, struct json_object *cur,
                return true;
 
        case T_OR:
+       case T_UNION:
                for (sop = op->down; sop; sop = sop->sibling)
                        if (jp_expr(sop, root, cur, idx, key, cb, priv))
                                return true;
index 75c33407586d39864d597a75d368a0bd8993cebc..e3b9ee989e489ff6c61674cfd77d5ae153448f5f 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -80,11 +80,11 @@ void jp_free(struct jp_state *s);
 
 
 %token T_ROOT T_THIS T_DOT T_BROPEN T_BRCLOSE
-%token T_OR T_AND T_LT T_LE T_GT T_GE T_EQ T_NE T_POPEN T_PCLOSE T_NOT
+%token T_OR T_AND T_LT T_LE T_GT T_GE T_EQ T_NE T_POPEN T_PCLOSE T_NOT T_UNION
 
 %token <op> T_BOOL T_NUMBER T_STRING T_LABEL T_WILDCARD
 
-%type <op> expr path segments segment or_exps or_exp and_exps and_exp cmp_exp unary_exp
+%type <op> expr path segments segment union_exps union_exp or_exps or_exp and_exps and_exp cmp_exp unary_exp
 
 %error-verbose
 
@@ -112,7 +112,16 @@ segments
 segment
        : T_DOT T_LABEL                                 { $$ = $2; }
        | T_DOT T_WILDCARD                              { $$ = $2; }
-       | T_BROPEN or_exps T_BRCLOSE    { $$ = $2; }
+       | T_BROPEN union_exps T_BRCLOSE { $$ = $2; }
+       ;
+
+union_exps
+       : union_exp                                             { $$ = $1->sibling ? jp_alloc_op(T_UNION, 0, NULL, $1) : $1; }
+       ;
+
+union_exp
+       : union_exp T_UNION or_exps             { $$ = append_op($1, $3); }
+       | or_exps                                               { $$ = $1; }
        ;
 
 or_exps