66
77grammar EqlBase;
88
9- tokens {
10- DELIMITER
11- }
129
1310singleStatement
1411 : statement EOF
@@ -19,45 +16,54 @@ singleExpression
1916 ;
2017
2118statement
22- : query ( PIPE pipe) *
19+ : query pipe*
2320 ;
24-
21+
2522query
2623 : sequence
2724 | join
28- | condition
25+ | eventQuery
26+ ;
27+
28+ sequenceParams
29+ : WITH (MAXSPAN EQ timeUnit)
2930 ;
30-
31+
3132sequence
32- : SEQUENCE (by=joinKeys)? (span )?
33- match +
34- (UNTIL match )?
33+ : SEQUENCE (by=joinKeys sequenceParams? | sequenceParams by=joinKeys? )?
34+ sequenceTerm sequenceTerm +
35+ (UNTIL sequenceTerm )?
3536 ;
3637
3738join
3839 : JOIN (by=joinKeys)?
39- match +
40- (UNTIL match )?
40+ joinTerm joinTerm +
41+ (UNTIL joinTerm )?
4142 ;
4243
4344pipe
44- : kind=IDENTIFIER (booleanExpression (COMMA booleanExpression)*)?
45+ : PIPE kind=IDENTIFIER (booleanExpression (COMMA booleanExpression)*)?
4546 ;
4647
48+
4749joinKeys
48- : BY qualifiedNames
49- ;
50-
51- span
52- : WITH MAXSPAN EQ DIGIT_IDENTIFIER
50+ : BY expression (COMMA expression)*
5351 ;
5452
55- match
56- : LB condition RB (by=joinKeys)?
53+ joinTerm
54+ : subquery (by=joinKeys)?
55+ ;
56+
57+ sequenceTerm
58+ : subquery (FORK (EQ booleanValue)?)? (by=joinKeys)?
59+ ;
60+
61+ subquery
62+ : LB eventQuery RB
5763 ;
5864
59- condition
60- : event=qualifiedName WHERE expression
65+ eventQuery
66+ : event=identifier WHERE expression
6167 ;
6268
6369expression
@@ -66,34 +72,28 @@ expression
6672
6773booleanExpression
6874 : NOT booleanExpression #logicalNot
69- | predicated #booleanDefault
75+ | relationship=IDENTIFIER OF subquery #processCheck
76+ | valueExpression #booleanDefault
7077 | left=booleanExpression operator=AND right=booleanExpression #logicalBinary
7178 | left=booleanExpression operator=OR right=booleanExpression #logicalBinary
7279 ;
7380
74- // workaround for:
75- // https://github.com/antlr/antlr4/issues/780
76- // https://github.com/antlr/antlr4/issues/781
77- predicated
78- : valueExpression predicate?
79- ;
80-
81- // dedicated calls for each branch are not used to reuse the NOT handling across them
82- // instead the property kind is used for differentiation
83- predicate
84- : NOT ? kind=BETWEEN lower=valueExpression AND upper=valueExpression
85- | NOT ? kind=IN LP valueExpression (COMMA valueExpression)* RP
86- | NOT ? kind=IN LP query RP
87- ;
8881
8982valueExpression
90- : primaryExpression #valueExpressionDefault
83+ : primaryExpression predicate? #valueExpressionDefault
9184 | operator=(MINUS | PLUS ) valueExpression #arithmeticUnary
9285 | left=valueExpression operator=(ASTERISK | SLASH | PERCENT ) right=valueExpression #arithmeticBinary
9386 | left=valueExpression operator=(PLUS | MINUS ) right=valueExpression #arithmeticBinary
9487 | left=valueExpression comparisonOperator right=valueExpression #comparison
9588 ;
9689
90+ // workaround for
91+ // https://github.com/antlr/antlr4/issues/780
92+ // https://github.com/antlr/antlr4/issues/781
93+ predicate
94+ : NOT ? kind=IN LP expression (COMMA expression)* RP
95+ ;
96+
9797primaryExpression
9898 : constant #constantDefault
9999 | functionExpression #function
@@ -102,14 +102,14 @@ primaryExpression
102102 ;
103103
104104functionExpression
105- : identifier LP (expression (COMMA expression)*)? RP
105+ : name= IDENTIFIER LP (expression (COMMA expression)*)? RP
106106 ;
107107
108108constant
109109 : NULL #nullLiteral
110110 | number #numericLiteral
111111 | booleanValue #booleanLiteral
112- | STRING + #stringLiteral
112+ | string #stringLiteral
113113 ;
114114
115115comparisonOperator
@@ -120,26 +120,17 @@ booleanValue
120120 : TRUE | FALSE
121121 ;
122122
123- qualifiedNames
124- : qualifiedName (COMMA qualifiedName)*
125- ;
126-
127123qualifiedName
128- : ( identifier DOT )* identifier
124+ : identifier ( DOT identifier | LB INTEGER_VALUE + RB )*
129125 ;
130126
131127identifier
132- : quoteIdentifier
133- | unquoteIdentifier
128+ : IDENTIFIER
129+ | ESCAPED_IDENTIFIER
134130 ;
135131
136- quoteIdentifier
137- : QUOTED_IDENTIFIER #quotedIdentifier
138- ;
139-
140- unquoteIdentifier
141- : IDENTIFIER #unquotedIdentifier
142- | DIGIT_IDENTIFIER #digitIdentifier
132+ timeUnit
133+ : number unit=IDENTIFIER ?
143134 ;
144135
145136number
@@ -151,31 +142,26 @@ string
151142 : STRING
152143 ;
153144
154- AND : ' AND' ;
155- ANY : ' ANY' ;
156- ASC : ' ASC' ;
157- BETWEEN : ' BETWEEN' ;
158- BY : ' BY' ;
159- CHILD : ' CHILD' ;
160- DESCENDANT : ' DESCENDANT' ;
161- EVENT : ' EVENT' ;
162- FALSE : ' FALSE' ;
163- IN : ' IN' ;
164- JOIN : ' JOIN' ;
165- MAXSPAN : ' MAXSPAN' ;
166- NOT : ' NOT' ;
167- NULL : ' NULL' ;
168- OF : ' OF' ;
169- OR : ' OR' ;
170- SEQUENCE : ' SEQUENCE' ;
171- TRUE : ' TRUE' ;
172- UNTIL : ' UNTIL' ;
173- WHERE : ' WHERE' ;
174- WITH : ' WITH' ;
145+ AND : ' and' ;
146+ BY : ' by' ;
147+ FALSE : ' false' ;
148+ FORK : ' fork' ;
149+ IN : ' in' ;
150+ JOIN : ' join' ;
151+ MAXSPAN : ' maxspan' ;
152+ NOT : ' not' ;
153+ NULL : ' null' ;
154+ OF : ' of' ;
155+ OR : ' or' ;
156+ SEQUENCE : ' sequence' ;
157+ TRUE : ' true' ;
158+ UNTIL : ' until' ;
159+ WHERE : ' where' ;
160+ WITH : ' with' ;
175161
176162// Operators
177163EQ : ' =' | ' ==' ;
178- NEQ : ' <> ' | ' !=' ;
164+ NEQ : ' !=' ;
179165LT : ' <' ;
180166LTE : ' <=' ;
181167GT : ' >' ;
@@ -194,9 +180,16 @@ LP: '(';
194180RP : ' )' ;
195181PIPE : ' |' ;
196182
183+
184+ ESCAPED_IDENTIFIER
185+ : ' `' (~' `' )* ' `'
186+ ;
187+
197188STRING
198- : ' \' ' ( ~' \' ' )* ' \' '
199- | ' "' ( ~' "' )* ' "'
189+ : ' \' ' (' \\ ' [btnfr" '\\ ] | ~[\r\n '\\ ])* '\' '
190+ | '" ' (' \\' [btnfr"' \\] | ~[\r\n" \\ ])* '" '
191+ | ' ?" ' ('\\ " ' |~["\r\n ])* ' " '
192+ | '?\' ' ('\\\' ' |~['\r\n ])* '\' '
200193 ;
201194
202195INTEGER_VALUE
@@ -210,31 +203,24 @@ DECIMAL_VALUE
210203 | DOT DIGIT+ EXPONENT
211204 ;
212205
206+ // make @timestamp not require escaping, since @ has no other meaning
213207IDENTIFIER
214- : (LETTER | ' _' ) (LETTER | DIGIT | ' _' | ' @' )*
215- ;
216-
217- DIGIT_IDENTIFIER
218- : DIGIT (LETTER | DIGIT | ' _' | ' @' )+
208+ : (LETTER | '_' | '@') (LETTER | DIGIT | '_')*
219209 ;
220210
221- QUOTED_IDENTIFIER
222- : ' "' ( ~' "' | ' ""' )* ' "'
223- ;
224-
225211fragment EXPONENT
226- : ' E ' [+-]? DIGIT +
212+ : [Ee] [+-]? DIGIT+
227213 ;
228214
229215fragment DIGIT
230216 : [0-9]
231217 ;
232218
233219fragment LETTER
234- : [A -Z ]
220+ : [A-Za-z ]
235221 ;
236222
237- SIMPLE_COMMENT
223+ LINE_COMMENT
238224 : '//' ~[\r\n ]* '\r '? '\n '? -> channel(HIDDEN)
239225 ;
240226
246232 : [ \r\n\t ]+ -> channel(HIDDEN)
247233 ;
248234
235+
249236// Catch-all for anything we can't recognize.
250237// We use this to be able to ignore and recover all the text
251238// when splitting statements with DelimiterLexer
239+ /*
252240UNRECOGNIZED
253241 : .
254- ;
242+ ;
243+ */
0 commit comments