2018-09-18 22:42:38 +02:00
|
|
|
parser grammar FqlParser;
|
|
|
|
|
|
|
|
options { tokenVocab=FqlLexer; }
|
|
|
|
|
|
|
|
program
|
|
|
|
: body
|
|
|
|
;
|
|
|
|
|
|
|
|
body
|
|
|
|
: (bodyStatement)* bodyExpression
|
|
|
|
;
|
|
|
|
|
|
|
|
bodyStatement
|
|
|
|
: functionCallExpression
|
|
|
|
| variableDeclaration
|
|
|
|
;
|
|
|
|
|
|
|
|
bodyExpression
|
|
|
|
: returnExpression
|
|
|
|
| forExpression
|
|
|
|
;
|
|
|
|
|
|
|
|
returnExpression
|
|
|
|
: Return (Distinct)? expression
|
|
|
|
| Return (Distinct)? OpenParen forExpression CloseParen
|
2018-09-28 01:05:56 +02:00
|
|
|
| Return forTernaryExpression
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
forExpression
|
|
|
|
: For forExpressionValueVariable (Comma forExpressionKeyVariable)? In forExpressionSource
|
|
|
|
(forExpressionBody)*
|
|
|
|
forExpressionReturn
|
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionValueVariable
|
|
|
|
: Identifier
|
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionKeyVariable
|
|
|
|
: Identifier
|
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionSource
|
|
|
|
: functionCallExpression
|
|
|
|
| arrayLiteral
|
|
|
|
| objectLiteral
|
|
|
|
| variable
|
|
|
|
| memberExpression
|
2018-09-23 01:18:10 +02:00
|
|
|
| rangeOperator
|
2018-09-29 03:04:16 +02:00
|
|
|
| param
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionClause
|
|
|
|
: limitClause
|
|
|
|
| sortClause
|
|
|
|
| filterClause
|
|
|
|
| collectClause
|
|
|
|
;
|
|
|
|
|
2018-10-28 07:45:26 +02:00
|
|
|
forExpressionStatement
|
|
|
|
: variableDeclaration
|
|
|
|
| functionCallExpression
|
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionBody
|
|
|
|
: forExpressionStatement
|
|
|
|
| forExpressionClause
|
|
|
|
;
|
|
|
|
|
|
|
|
forExpressionReturn
|
|
|
|
: returnExpression
|
|
|
|
| forExpression
|
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
filterClause
|
|
|
|
: Filter expression
|
|
|
|
;
|
|
|
|
|
|
|
|
limitClause
|
2018-11-13 02:58:12 +02:00
|
|
|
: Limit limitClauseValue (Comma limitClauseValue)?
|
|
|
|
;
|
|
|
|
|
|
|
|
limitClauseValue
|
|
|
|
: IntegerLiteral
|
|
|
|
| param
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
sortClause
|
2018-09-23 01:18:10 +02:00
|
|
|
: Sort sortClauseExpression (Comma sortClauseExpression)*
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
sortClauseExpression
|
|
|
|
: expression SortDirection?
|
|
|
|
;
|
|
|
|
|
|
|
|
collectClause
|
2018-10-25 03:30:05 +02:00
|
|
|
: Collect collectCounter
|
|
|
|
| Collect collectAggregator
|
|
|
|
| Collect collectGrouping collectAggregator
|
|
|
|
| Collect collectGrouping collectGroupVariable
|
|
|
|
| Collect collectGrouping collectCounter
|
|
|
|
| Collect collectGrouping
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectSelector
|
|
|
|
: Identifier Assign expression
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectGrouping
|
|
|
|
: collectSelector (Comma collectSelector)*
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectAggregator
|
|
|
|
: Aggregate collectAggregateSelector (Comma collectAggregateSelector)*
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectAggregateSelector
|
|
|
|
: Identifier Assign functionCallExpression
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectGroupVariable
|
|
|
|
: Into collectSelector
|
|
|
|
| Into Identifier (Keep Identifier)?
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-10-25 03:30:05 +02:00
|
|
|
collectCounter
|
|
|
|
: With Count Into Identifier
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
variableDeclaration
|
|
|
|
: Let Identifier Assign expression
|
|
|
|
| Let Identifier Assign OpenParen forExpression CloseParen
|
2018-09-28 01:05:56 +02:00
|
|
|
| Let Identifier Assign forTernaryExpression
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-09-29 03:04:16 +02:00
|
|
|
param
|
|
|
|
: Param Identifier
|
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
variable
|
|
|
|
: Identifier
|
|
|
|
;
|
|
|
|
|
2018-09-23 01:18:10 +02:00
|
|
|
rangeOperator
|
2018-09-29 03:04:16 +02:00
|
|
|
: (integerLiteral | variable | param) Range (integerLiteral | variable | param)
|
2018-09-23 01:18:10 +02:00
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
arrayLiteral
|
|
|
|
: OpenBracket arrayElementList? CloseBracket
|
|
|
|
;
|
|
|
|
|
|
|
|
objectLiteral
|
|
|
|
: OpenBrace (propertyAssignment (Comma propertyAssignment)*)? Comma? CloseBrace
|
|
|
|
;
|
|
|
|
|
|
|
|
booleanLiteral
|
|
|
|
: BooleanLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
stringLiteral
|
|
|
|
: StringLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
integerLiteral
|
|
|
|
: IntegerLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
floatLiteral
|
|
|
|
: FloatLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
noneLiteral
|
|
|
|
: Null
|
|
|
|
| None
|
|
|
|
;
|
|
|
|
|
|
|
|
arrayElementList
|
|
|
|
: expression (Comma + expression)*
|
|
|
|
;
|
|
|
|
|
|
|
|
propertyAssignment
|
|
|
|
: propertyName Colon expression
|
|
|
|
| computedPropertyName Colon expression
|
|
|
|
| shorthandPropertyName
|
|
|
|
;
|
|
|
|
|
|
|
|
shorthandPropertyName
|
|
|
|
: variable
|
|
|
|
;
|
|
|
|
|
|
|
|
computedPropertyName
|
|
|
|
: OpenBracket expression CloseBracket
|
|
|
|
;
|
|
|
|
|
|
|
|
propertyName
|
|
|
|
: Identifier
|
2018-10-22 21:11:00 +02:00
|
|
|
| stringLiteral
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
expressionGroup
|
|
|
|
: OpenParen expression CloseParen
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2019-05-10 18:53:31 +02:00
|
|
|
namespace
|
|
|
|
: (NamespaceSegment)*
|
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
functionCallExpression
|
2019-05-10 18:53:31 +02:00
|
|
|
: namespace Identifier arguments
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2019-09-07 07:21:43 +02:00
|
|
|
member
|
|
|
|
: Identifier
|
|
|
|
| functionCallExpression
|
|
|
|
| param
|
|
|
|
;
|
|
|
|
|
|
|
|
memberPath
|
|
|
|
: (Dot propertyName (computedPropertyName)*)+
|
|
|
|
| computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
|
|
|
|
;
|
|
|
|
|
2019-09-01 22:01:03 +02:00
|
|
|
memberExpression
|
2019-09-07 07:21:43 +02:00
|
|
|
: member memberPath
|
2019-09-01 22:01:03 +02:00
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
arguments
|
|
|
|
: OpenParen(expression (Comma expression)*)?CloseParen
|
|
|
|
;
|
|
|
|
|
|
|
|
expression
|
2018-10-17 17:41:40 +02:00
|
|
|
: unaryOperator expression
|
2018-12-22 06:14:41 +02:00
|
|
|
| expression multiplicativeOperator expression
|
|
|
|
| expression additiveOperator expression
|
2018-09-18 22:42:38 +02:00
|
|
|
| functionCallExpression
|
2018-12-22 06:14:41 +02:00
|
|
|
| expressionGroup
|
2018-10-17 17:41:40 +02:00
|
|
|
| expression arrayOperator (inOperator | equalityOperator) expression
|
|
|
|
| expression inOperator expression
|
2018-12-22 06:14:41 +02:00
|
|
|
| expression equalityOperator expression
|
2019-07-09 20:19:53 +02:00
|
|
|
| expression regexpOperator expression
|
2018-12-22 06:14:41 +02:00
|
|
|
| expression logicalAndOperator expression
|
|
|
|
| expression logicalOrOperator expression
|
2018-09-22 17:24:35 +02:00
|
|
|
| expression QuestionMark expression? Colon expression
|
2018-09-23 01:18:10 +02:00
|
|
|
| rangeOperator
|
2018-09-18 22:42:38 +02:00
|
|
|
| stringLiteral
|
|
|
|
| integerLiteral
|
|
|
|
| floatLiteral
|
|
|
|
| booleanLiteral
|
|
|
|
| arrayLiteral
|
|
|
|
| objectLiteral
|
|
|
|
| variable
|
|
|
|
| memberExpression
|
|
|
|
| noneLiteral
|
2018-09-29 03:04:16 +02:00
|
|
|
| param
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
2018-09-28 01:05:56 +02:00
|
|
|
forTernaryExpression
|
|
|
|
: expression QuestionMark expression? Colon OpenParen forExpression CloseParen
|
|
|
|
| expression QuestionMark OpenParen forExpression CloseParen Colon expression
|
|
|
|
| expression QuestionMark OpenParen forExpression CloseParen Colon OpenParen forExpression CloseParen
|
|
|
|
;
|
|
|
|
|
2018-10-07 23:54:02 +02:00
|
|
|
arrayOperator
|
|
|
|
: All
|
|
|
|
| Any
|
|
|
|
| None
|
|
|
|
;
|
|
|
|
|
|
|
|
inOperator
|
|
|
|
: In
|
2018-10-17 17:41:40 +02:00
|
|
|
| Not In
|
2018-10-07 23:54:02 +02:00
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
equalityOperator
|
|
|
|
: Gt
|
|
|
|
| Lt
|
|
|
|
| Eq
|
|
|
|
| Gte
|
|
|
|
| Lte
|
|
|
|
| Neq
|
|
|
|
;
|
|
|
|
|
2019-07-09 20:19:53 +02:00
|
|
|
regexpOperator
|
|
|
|
: RegexMatch
|
|
|
|
| RegexNotMatch
|
|
|
|
;
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
logicalAndOperator
|
2018-09-18 22:42:38 +02:00
|
|
|
: And
|
|
|
|
;
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
logicalOrOperator
|
|
|
|
: Or
|
|
|
|
;
|
|
|
|
|
|
|
|
multiplicativeOperator
|
|
|
|
: Multi
|
2018-09-18 22:42:38 +02:00
|
|
|
| Div
|
|
|
|
| Mod
|
|
|
|
;
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
additiveOperator
|
|
|
|
: Plus
|
|
|
|
| Minus
|
|
|
|
;
|
|
|
|
|
2018-09-18 22:42:38 +02:00
|
|
|
unaryOperator
|
|
|
|
: Not
|
2018-09-28 01:05:56 +02:00
|
|
|
| Plus
|
2018-09-18 22:42:38 +02:00
|
|
|
| Minus
|
|
|
|
| Like
|
|
|
|
;
|