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
|
2018-10-16 00:50:55 +02:00
|
|
|
| TemplateStringLiteral
|
2018-09-18 22:42:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
integerLiteral
|
|
|
|
: IntegerLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
floatLiteral
|
|
|
|
: FloatLiteral
|
|
|
|
;
|
|
|
|
|
|
|
|
noneLiteral
|
|
|
|
: Null
|
|
|
|
| None
|
|
|
|
;
|
|
|
|
|
|
|
|
arrayElementList
|
|
|
|
: expression (Comma + expression)*
|
|
|
|
;
|
|
|
|
|
|
|
|
propertyAssignment
|
|
|
|
: propertyName Colon expression
|
|
|
|
| computedPropertyName Colon expression
|
|
|
|
| shorthandPropertyName
|
|
|
|
;
|
|
|
|
|
|
|
|
memberExpression
|
|
|
|
: Identifier (Dot propertyName (computedPropertyName)*)+
|
|
|
|
| Identifier computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
|
|
|
|
;
|
|
|
|
|
|
|
|
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
|
|
|
;
|
|
|
|
|
|
|
|
expressionSequence
|
|
|
|
: expression (Comma expression)*
|
|
|
|
;
|
|
|
|
|
|
|
|
functionCallExpression
|
|
|
|
: Identifier arguments
|
|
|
|
;
|
|
|
|
|
|
|
|
arguments
|
|
|
|
: OpenParen(expression (Comma expression)*)?CloseParen
|
|
|
|
;
|
|
|
|
|
|
|
|
expression
|
2018-10-17 17:41:40 +02:00
|
|
|
: unaryOperator expression
|
|
|
|
| expression equalityOperator expression
|
2018-09-18 22:42:38 +02:00
|
|
|
| expression logicalOperator expression
|
|
|
|
| expression mathOperator expression
|
|
|
|
| functionCallExpression
|
|
|
|
| OpenParen expressionSequence CloseParen
|
2018-10-17 17:41:40 +02:00
|
|
|
| expression arrayOperator (inOperator | equalityOperator) expression
|
|
|
|
| expression inOperator 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
|
|
|
|
;
|
|
|
|
|
|
|
|
logicalOperator
|
|
|
|
: And
|
|
|
|
| Or
|
|
|
|
;
|
|
|
|
|
|
|
|
mathOperator
|
|
|
|
: Plus
|
|
|
|
| Minus
|
|
|
|
| Multi
|
|
|
|
| Div
|
|
|
|
| Mod
|
|
|
|
;
|
|
|
|
|
|
|
|
unaryOperator
|
|
|
|
: Not
|
2018-09-28 01:05:56 +02:00
|
|
|
| Plus
|
2018-09-18 22:42:38 +02:00
|
|
|
| Minus
|
|
|
|
| Like
|
|
|
|
;
|