• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/jsonpath/parser.y

  1 /*
  2  * Copyright (C) 2013-2014 Jo-Philipp Wich <jo@mein.io>
  3  *
  4  * Permission to use, copy, modify, and/or distribute this software for any
  5  * purpose with or without fee is hereby granted, provided that the above
  6  * copyright notice and this permission notice appear in all copies.
  7  *
  8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15  */
 16 
 17 %token_type {struct jp_opcode *}
 18 %extra_argument {struct jp_state *s}
 19 
 20 %left T_AND.
 21 %left T_OR.
 22 %left T_UNION.
 23 %nonassoc T_EQ T_NE T_GT T_GE T_LT T_LE T_MATCH.
 24 %right T_NOT.
 25 
 26 %include {
 27 #include <assert.h>
 28 #include <stddef.h>
 29 #include <stdlib.h>
 30 #include <string.h>
 31 
 32 #include "ast.h"
 33 #include "lexer.h"
 34 #include "parser.h"
 35 
 36 #define alloc_op(type, num, str, ...) \
 37         jp_alloc_op(s, type, num, str, ##__VA_ARGS__, NULL)
 38 
 39 }
 40 
 41 %syntax_error {
 42         int i;
 43 
 44         for (i = 0; i < sizeof(tokennames) / sizeof(tokennames[0]); i++)
 45                 if (yy_find_shift_action(yypParser, (YYCODETYPE)i) < YYNSTATE + YYNRULE)
 46                         s->error_code |= (1 << i);
 47 
 48         s->error_pos = s->off;
 49 }
 50 
 51 
 52 input ::= expr(A).                                                                      { s->path = A; }
 53 
 54 expr(A) ::= T_LABEL(B) T_EQ path(C).                            { A = B; B->down = C; }
 55 expr(A) ::= path(B).                                                            { A = B; }
 56 
 57 path(A) ::= T_ROOT segments(B).                                         { A = alloc_op(T_ROOT, 0, NULL, B); }
 58 path(A) ::= T_THIS segments(B).                                         { A = alloc_op(T_THIS, 0, NULL, B); }
 59 path(A) ::= T_ROOT(B).                                                          { A = B; }
 60 path(A) ::= T_THIS(B).                                                          { A = B; }
 61 
 62 segments(A) ::= segments(B) segment(C).                         { A = append_op(B, C); }
 63 segments(A) ::= segment(B).                                                     { A = B; }
 64 
 65 segment(A) ::= T_DOT T_LABEL(B).                                        { A = B; }
 66 segment(A) ::= T_DOT T_WILDCARD(B).                                     { A = B; }
 67 segment(A) ::= T_BROPEN union_exps(B) T_BRCLOSE.        { A = B; }
 68 
 69 union_exps(A) ::= union_exp(B).                                         { A = B->sibling ? alloc_op(T_UNION, 0, NULL, B) : B; }
 70 
 71 union_exp(A) ::= union_exp(B) T_UNION or_exps(C).       { A = append_op(B, C); }
 72 union_exp(A) ::= or_exps(B).                                            { A = B; }
 73 
 74 or_exps(A) ::= or_exp(B).                                                       { A = B->sibling ? alloc_op(T_OR, 0, NULL, B) : B; }
 75 
 76 or_exp(A) ::= or_exp(B) T_OR and_exps(C).                       { A = append_op(B, C); }
 77 or_exp(A) ::= and_exps(B).                                                      { A = B; }
 78 
 79 and_exps(A) ::= and_exp(B).                                                     { A = B->sibling ? alloc_op(T_AND, 0, NULL, B) : B; }
 80 
 81 and_exp(A) ::= and_exp(B) T_AND cmp_exp(C).                     { A = append_op(B, C); }
 82 and_exp(A) ::= cmp_exp(B).                                                      { A = B; }
 83 
 84 cmp_exp(A) ::= unary_exp(B) T_LT unary_exp(C).          { A = alloc_op(T_LT, 0, NULL, B, C); }
 85 cmp_exp(A) ::= unary_exp(B) T_LE unary_exp(C).          { A = alloc_op(T_LE, 0, NULL, B, C); }
 86 cmp_exp(A) ::= unary_exp(B) T_GT unary_exp(C).          { A = alloc_op(T_GT, 0, NULL, B, C); }
 87 cmp_exp(A) ::= unary_exp(B) T_GE unary_exp(C).          { A = alloc_op(T_GE, 0, NULL, B, C); }
 88 cmp_exp(A) ::= unary_exp(B) T_EQ unary_exp(C).          { A = alloc_op(T_EQ, 0, NULL, B, C); }
 89 cmp_exp(A) ::= unary_exp(B) T_NE unary_exp(C).          { A = alloc_op(T_NE, 0, NULL, B, C); }
 90 cmp_exp(A) ::= unary_exp(B) T_MATCH unary_exp(C).       { A = alloc_op(T_MATCH, 0, NULL, B, C); }
 91 cmp_exp(A) ::= unary_exp(B).                                            { A = B; }
 92 
 93 unary_exp(A) ::= T_BOOL(B).                                                     { A = B; }
 94 unary_exp(A) ::= T_NUMBER(B).                                           { A = B; }
 95 unary_exp(A) ::= T_STRING(B).                                           { A = B; }
 96 unary_exp(A) ::= T_REGEXP(B).                                           { A = B; }
 97 unary_exp(A) ::= T_WILDCARD(B).                                         { A = B; }
 98 unary_exp(A) ::= T_POPEN or_exps(B) T_PCLOSE.           { A = B; }
 99 unary_exp(A) ::= T_NOT unary_exp(B).                            { A = alloc_op(T_NOT, 0, NULL, B); }
100 unary_exp(A) ::= path(B).                                                       { A = B; }

This page was automatically generated by LXR 0.3.1.  •  OpenWrt