-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.g4
43 lines (28 loc) · 893 Bytes
/
select.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
grammar select;
// Complex tokens
select: num table filters order_by fields;
count: '#' table filters;
num: (NUMBERS '*')?;
table: ID;
filters: filtersFrag?;
filtersFrag: '(' filter (',' filter)* ')';
filter: filterFrag ('|' filterFrag)*;
filterFrag:
filtersFrag
| variable OP variable
| variable OP? '[' num_or_strings ']';
variable: num_or_string | ID;
order_by: ('{' ID (',' ID)* '}')?;
fields: ('[' (ID (',' ID)*)? ']')?;
num_or_strings: num_or_string (',' num_or_string)*;
num_or_string: TEXT | NUMBERS;
// Terminal tokens
OP: '>' | '<' | '<=' | '>=' | '=' | '!=' | '!';
ID: [a-zA-Z_][a-zA-Z_0-9]+;
// Allow decimal
NUMBERS: [0-9]+ | [0-9]* '.' [0-9]+;
TEXT:
'"' (~('\r' | '\n' | '\\' | '"') | '\\' ('"' | '\\'))* '"'
| '\'' (~('\r' | '\n' | '\'') | '\\' ('\'' | '\\'))* '\'';
// skip spaces, tabs, newlines
WS: [ \t\r\n]+ -> skip;