-
Notifications
You must be signed in to change notification settings - Fork 4
/
TExprParser.g4
143 lines (114 loc) · 2.14 KB
/
TExprParser.g4
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
parser grammar TExprParser;
options { tokenVocab=TExprLexer; }
parse
: expression EOF
;
expression
: LPAREN expression RPAREN #parenExpression
| NOT expression #notExpression
| expression IN container #inExpression
| expression NOT IN container #notInExpression
| expression MATCH regex #matchExpression
| expression IS kind #isTypeExpression
| expression IS NOT kind #isNotTypeExpression
| expression comparator expression #comparatorExpression
| expression binary expression #binaryExpression
| variable #variableExpression
| calc #calcExpression
;
variable
: VARIABLE
| literal
| array
;
comparator
: GT | GE | LT | LE | EQ | NE
;
binary
: AND | OR
;
boolean
: TRUE | FALSE
;
literal
: Varchar
| Integer
| Float
| Boolean
;
container
: array
| variable
| Varchar
;
array
: LBRACKET integers? RBRACKET
| LBRACKET strings? RBRACKET
| LBRACKET floats? RBRACKET
| LBRACKET booleans? RBRACKET
;
calc
: bit
;
bit
: bit BAND shift
| bit BEOR shift
| bit BIOR shift
| shift
;
shift
: shift LSHIFT plus
| shift RSHIFT plus
| plus
;
plus
: plus PLUS multiplying
| plus MINUS multiplying
| multiplying
;
multiplying
: multiplying MUL atom
| multiplying DIV atom
| multiplying MOD atom
| atom
;
atom
: variable
| scientific
| LPAREN bit RPAREN
| function
;
scientific
: number E number
| number
;
function
: funcname LPAREN parameters RPAREN
;
funcname
: IDENTIFIER
;
parameters
: expression (',' expression)*
;
number
: MINUS? DIGIT + (POINT DIGIT +)?
;
regex
: REGEX
;
kind
: IDENTIFIER
;
strings
: Varchar (COMMA Varchar)* COMMA?
;
integers
: Integer (COMMA Integer)* COMMA?
;
floats
: Float (COMMA Float)* COMMA?
;
booleans
: Boolean (COMMA Boolean)* COMMA?
;