github.com/MontFerret/ferret@v0.18.0/pkg/parser/antlr/FqlParser.g4 (about) 1 // $antlr-format off <-- used by VS Code Antlr extension 2 3 parser grammar FqlParser; 4 5 options { tokenVocab=FqlLexer; } 6 7 program 8 : head* body 9 ; 10 11 head 12 : useExpression 13 ; 14 15 useExpression 16 : use 17 ; 18 19 use 20 : Use namespaceIdentifier 21 ; 22 23 body 24 : bodyStatement* bodyExpression 25 ; 26 27 bodyStatement 28 : variableDeclaration 29 | functionCallExpression 30 | waitForExpression 31 ; 32 33 bodyExpression 34 : returnExpression 35 | forExpression 36 ; 37 38 variableDeclaration 39 : Let id=(Identifier | IgnoreIdentifier) Assign expression 40 | Let safeReservedWord Assign expression 41 ; 42 43 returnExpression 44 : Return (Distinct)? expression 45 ; 46 47 forExpression 48 : For valueVariable=(Identifier | IgnoreIdentifier) (Comma counterVariable=Identifier)? In forExpressionSource 49 forExpressionBody* 50 forExpressionReturn 51 | For counterVariable=(Identifier | IgnoreIdentifier) Do? While expression 52 forExpressionBody* 53 forExpressionReturn 54 ; 55 56 forExpressionSource 57 : functionCallExpression 58 | arrayLiteral 59 | objectLiteral 60 | variable 61 | memberExpression 62 | rangeOperator 63 | param 64 ; 65 66 forExpressionClause 67 : limitClause 68 | sortClause 69 | filterClause 70 | collectClause 71 ; 72 73 forExpressionStatement 74 : variableDeclaration 75 | functionCallExpression 76 ; 77 78 forExpressionBody 79 : forExpressionStatement 80 | forExpressionClause 81 ; 82 83 forExpressionReturn 84 : returnExpression 85 | forExpression 86 ; 87 88 filterClause 89 : Filter expression 90 ; 91 92 limitClause 93 : Limit limitClauseValue (Comma limitClauseValue)? 94 ; 95 96 limitClauseValue 97 : integerLiteral 98 | param 99 | variable 100 | functionCallExpression 101 | memberExpression 102 ; 103 104 sortClause 105 : Sort sortClauseExpression (Comma sortClauseExpression)* 106 ; 107 108 sortClauseExpression 109 : expression SortDirection? 110 ; 111 112 collectClause 113 : Collect collectCounter 114 | Collect collectAggregator 115 | Collect collectGrouping collectAggregator 116 | Collect collectGrouping collectGroupVariable 117 | Collect collectGrouping collectCounter 118 | Collect collectGrouping 119 ; 120 121 collectSelector 122 : Identifier Assign expression 123 ; 124 125 collectGrouping 126 : collectSelector (Comma collectSelector)* 127 ; 128 129 collectAggregator 130 : Aggregate collectAggregateSelector (Comma collectAggregateSelector)* 131 ; 132 133 collectAggregateSelector 134 : Identifier Assign functionCallExpression 135 ; 136 137 collectGroupVariable 138 : Into collectSelector 139 | Into Identifier (Keep Identifier)? 140 ; 141 142 collectCounter 143 : With Count Into Identifier 144 ; 145 146 waitForExpression 147 : Waitfor Event waitForEventName In waitForEventSource (optionsClause)? (filterClause)? (timeoutClause)? 148 ; 149 150 waitForEventName 151 : stringLiteral 152 | variable 153 | param 154 | functionCallExpression 155 | memberExpression 156 ; 157 158 waitForEventSource 159 : functionCallExpression 160 | variable 161 | memberExpression 162 ; 163 164 optionsClause 165 : Options objectLiteral 166 ; 167 168 timeoutClause 169 : Timeout (integerLiteral | variable | param | memberExpression | functionCall) 170 ; 171 172 param 173 : Param Identifier 174 | Param safeReservedWord 175 ; 176 177 variable 178 : Identifier 179 | safeReservedWord 180 ; 181 182 literal 183 : arrayLiteral 184 | objectLiteral 185 | booleanLiteral 186 | stringLiteral 187 | floatLiteral 188 | integerLiteral 189 | noneLiteral 190 ; 191 192 arrayLiteral 193 : OpenBracket argumentList? CloseBracket 194 ; 195 196 objectLiteral 197 : OpenBrace (propertyAssignment (Comma propertyAssignment)* Comma?)? CloseBrace 198 ; 199 200 booleanLiteral 201 : BooleanLiteral 202 ; 203 204 stringLiteral 205 : StringLiteral 206 ; 207 208 floatLiteral 209 : FloatLiteral 210 ; 211 212 integerLiteral 213 : IntegerLiteral 214 ; 215 216 noneLiteral 217 : Null 218 | None 219 ; 220 221 propertyAssignment 222 : propertyName Colon expression 223 | computedPropertyName Colon expression 224 | variable 225 ; 226 227 computedPropertyName 228 : OpenBracket expression CloseBracket 229 ; 230 231 propertyName 232 : Identifier 233 | stringLiteral 234 | param 235 | safeReservedWord 236 | unsafeReservedWord 237 ; 238 239 namespaceIdentifier 240 : namespace Identifier 241 ; 242 243 namespace 244 : NamespaceSegment* 245 ; 246 247 memberExpression 248 : memberExpressionSource memberExpressionPath+ 249 ; 250 251 memberExpressionSource 252 : variable 253 | param 254 | arrayLiteral 255 | objectLiteral 256 | functionCall 257 ; 258 259 functionCallExpression 260 : functionCall errorOperator? 261 ; 262 263 functionCall 264 : namespace functionName OpenParen argumentList? CloseParen 265 ; 266 267 functionName 268 : Identifier 269 | safeReservedWord 270 | unsafeReservedWord 271 ; 272 273 argumentList 274 : expression (Comma expression)* Comma? 275 ; 276 277 memberExpressionPath 278 : errorOperator? Dot propertyName 279 | (errorOperator Dot)? computedPropertyName 280 ; 281 282 safeReservedWord 283 : And 284 | Or 285 | Distinct 286 | Filter 287 | Sort 288 | Limit 289 | Collect 290 | SortDirection 291 | Into 292 | Keep 293 | With 294 | Count 295 | All 296 | Any 297 | Aggregate 298 | Event 299 | Timeout 300 | Options 301 | Current 302 ; 303 304 unsafeReservedWord 305 : Return 306 | None 307 | Null 308 | Let 309 | Use 310 | Waitfor 311 | While 312 | Do 313 | In 314 | Like 315 | Not 316 | For 317 | BooleanLiteral 318 ; 319 320 rangeOperator 321 : left=rangeOperand Range right=rangeOperand 322 ; 323 324 rangeOperand 325 : integerLiteral 326 | variable 327 | param 328 ; 329 330 expression 331 : unaryOperator right=expression 332 | left=expression logicalAndOperator right=expression 333 | left=expression logicalOrOperator right=expression 334 | condition=expression ternaryOperator=QuestionMark onTrue=expression? Colon onFalse=expression 335 | predicate 336 ; 337 338 predicate 339 : left=predicate equalityOperator right=predicate 340 | left=predicate arrayOperator right=predicate 341 | left=predicate inOperator right=predicate 342 | left=predicate likeOperator right=predicate 343 | expressionAtom 344 ; 345 346 expressionAtom 347 : left=expressionAtom multiplicativeOperator right=expressionAtom 348 | left=expressionAtom additiveOperator right=expressionAtom 349 | left=expressionAtom regexpOperator right=expressionAtom 350 | functionCallExpression 351 | rangeOperator 352 | literal 353 | variable 354 | memberExpression 355 | param 356 | OpenParen (forExpression | waitForExpression | expression) CloseParen errorOperator? 357 ; 358 359 arrayOperator 360 : operator=(All | Any | None) (inOperator | equalityOperator) 361 ; 362 363 equalityOperator 364 : Gt 365 | Lt 366 | Eq 367 | Gte 368 | Lte 369 | Neq 370 ; 371 372 inOperator 373 : Not? In 374 ; 375 376 likeOperator 377 : Not? Like 378 ; 379 380 unaryOperator 381 : Not 382 | Plus 383 | Minus 384 ; 385 386 regexpOperator 387 : RegexMatch 388 | RegexNotMatch 389 ; 390 391 logicalAndOperator 392 : And 393 ; 394 395 logicalOrOperator 396 : Or 397 ; 398 399 multiplicativeOperator 400 : Multi 401 | Div 402 | Mod 403 ; 404 405 additiveOperator 406 : Plus 407 | Minus 408 ; 409 410 errorOperator 411 : QuestionMark 412 ;