-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathgrammar.py
More file actions
26 lines (26 loc) · 884 Bytes
/
grammar.py
File metadata and controls
26 lines (26 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
grammar_definition = """
start: expr
expr: term | expr OR term
term: factor | term AND factor
factor: compare_expr
?quoted_string : DOUBLE_QUOTED_STRING | SINGLE_QUOTED_STRING
compare_expr: (NAME | array | quoted_string) COMPARE_OP (NAME | array | quoted_string)
VALUE: NUMBER | CNAME | SINGLE_QUOTED_STRING | DOUBLE_QUOTED_STRING
COMPARE_OP: "!=" | ">=" | "<=" | ">" | "<" | "=" | "in"
OR: "or"
AND: "and"
NAME: CNAME [DOT CNAME]+ | CNAME | NUMBER
array: "[" [VALUE ("," VALUE)*] "]"
DOT: "."
AMPERSAND: "&"
CNAME: ("_"|LETTER|"&"|"?") ("_"|LETTER|DIGIT|"&"|"?")*
DOUBLE_QUOTED_STRING : /"[^"]*"/
SINGLE_QUOTED_STRING : /'[^']*'/
%import common.NUMBER
%import common.LETTER
%import common.DIGIT
%import common.NEWLINE
%ignore NEWLINE
_WHITESPACE: /[ \t]+/
%ignore _WHITESPACE
"""