-
Notifications
You must be signed in to change notification settings - Fork 505
Expand file tree
/
Copy pathquery.g4
More file actions
144 lines (117 loc) · 2.27 KB
/
query.g4
File metadata and controls
144 lines (117 loc) · 2.27 KB
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
144
grammar Query;
// Kind of a simplified, restructured variant of the Clojure/Java lexers with a
// way different structure.
//
// https://github.com/antlr/grammars-v4/blob/master/clojure/Clojure.g4
predicate
: primary
| 'not' predicate
| predicate 'and' predicate
| predicate 'or' predicate
;
primary
: '(' predicate ')'
| simple
;
simple
: tagged
| equal
| not_equal
| lesser
| greater
| lesser_equal
| greater_equal
| like
| regex_match
| field
| value
;
tagged : 'tagged' string ;
equal : value '=' value ;
not_equal : value '!=' value ;
lesser : value '<' number ;
greater : value '>' number ;
lesser_equal : value '<=' number ;
greater_equal : value '>=' number ;
like : value '=~' string ;
regex_match : value '~=' string ;
// Values -----------------------------------------------------------
value
: true
| false
| nil
| number
| string
| field
;
field : NAME ;
string : STRING ;
true : TRUE ;
false : FALSE ;
nil : NIL ;
number
: float
| bign
| long
;
float : FLOAT;
bign : BIGN;
long : LONG;
// Lexers -------------------------------------------------------------
STRING : '"' ( ~'"' | '\\' '"' )* '"' ;
FLOAT
: '-'? [0-9]+ FLOAT_TAIL
| '-'? 'Infinity'
| '-'? 'NaN'
;
fragment
FLOAT_TAIL
: FLOAT_DECIMAL FLOAT_EXP
| FLOAT_DECIMAL
| FLOAT_EXP
;
fragment
FLOAT_DECIMAL
: '.' [0-9]+
;
fragment
FLOAT_EXP
: [eE] '-'? [0-9]+
;
fragment
HEXD: [0-9a-fA-F] ;
HEX: '0' [xX] HEXD+ ;
LONG: '-'? [0-9]+[lL]?;
BIGN: '-'? [0-9]+[nN];
CHAR_U
: '\\' 'u'[0-9D-Fd-f] HEXD HEXD HEXD ;
CHAR_NAMED
: '\\' ( 'newline'
| 'return'
| 'space'
| 'tab'
| 'formfeed'
| 'backspace' ) ;
CHAR_ANY
: '\\' . ;
NIL : 'nil'
| 'null' ;
TRUE : 'true' ;
FALSE : 'false' ;
// Names
NAME: SYMBOL_HEAD SYMBOL_REST* (':' SYMBOL_REST+)* ;
fragment
SYMBOL_HEAD
: ~('0' .. '9'
| '^' | '`' | '\'' | '"' | '#' | '~' | '@' | ':' | '/' | '%' | '(' | ')' | '[' | ']' | '{' | '}' // FIXME: could be one group
| [ \n\r\t\,] // FIXME: could be WS
)
;
fragment
SYMBOL_REST
: SYMBOL_HEAD
| '0'..'9'
| '.'
;
// Whitespace
WS : [ \n\r\t\,] -> channel(HIDDEN) ;