mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
5620be211c
* Renamed DOCUMENT to PAGE * Added PageLoadParams * Added PageLoadParams * Renamed LoadPageParams -> PageLoadParams * Added support for context.Done() (#201) * Bug/#189 operators precedence (#202) * Fixed math operators precedence * Fixed logical operators precedence * Fixed array operator * Added support for parentheses to enforce a different operator evaluation order * Feature/#200 drivers (#209) * Added new interfaces * Renamed dynamic to cdp driver * Renamed drivers * Added ELEMENT_EXISTS function (#210) * Renamed back PAGE to DOCUMENT (#211) * Added Getter and Setter interfaces
293 lines
5.1 KiB
ANTLR
293 lines
5.1 KiB
ANTLR
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
|
|
| Return forTernaryExpression
|
|
;
|
|
|
|
forExpression
|
|
: For forExpressionValueVariable (Comma forExpressionKeyVariable)? In forExpressionSource
|
|
(forExpressionBody)*
|
|
forExpressionReturn
|
|
;
|
|
|
|
forExpressionValueVariable
|
|
: Identifier
|
|
;
|
|
|
|
forExpressionKeyVariable
|
|
: Identifier
|
|
;
|
|
|
|
forExpressionSource
|
|
: functionCallExpression
|
|
| arrayLiteral
|
|
| objectLiteral
|
|
| variable
|
|
| memberExpression
|
|
| rangeOperator
|
|
| param
|
|
;
|
|
|
|
forExpressionClause
|
|
: limitClause
|
|
| sortClause
|
|
| filterClause
|
|
| collectClause
|
|
;
|
|
|
|
forExpressionStatement
|
|
: variableDeclaration
|
|
| functionCallExpression
|
|
;
|
|
|
|
forExpressionBody
|
|
: forExpressionStatement
|
|
| forExpressionClause
|
|
;
|
|
|
|
forExpressionReturn
|
|
: returnExpression
|
|
| forExpression
|
|
;
|
|
|
|
filterClause
|
|
: Filter expression
|
|
;
|
|
|
|
limitClause
|
|
: Limit limitClauseValue (Comma limitClauseValue)?
|
|
;
|
|
|
|
limitClauseValue
|
|
: IntegerLiteral
|
|
| param
|
|
;
|
|
|
|
sortClause
|
|
: Sort sortClauseExpression (Comma sortClauseExpression)*
|
|
;
|
|
|
|
sortClauseExpression
|
|
: expression SortDirection?
|
|
;
|
|
|
|
collectClause
|
|
: Collect collectCounter
|
|
| Collect collectAggregator
|
|
| Collect collectGrouping collectAggregator
|
|
| Collect collectGrouping collectGroupVariable
|
|
| Collect collectGrouping collectCounter
|
|
| Collect collectGrouping
|
|
;
|
|
|
|
collectSelector
|
|
: Identifier Assign expression
|
|
;
|
|
|
|
collectGrouping
|
|
: collectSelector (Comma collectSelector)*
|
|
;
|
|
|
|
collectAggregator
|
|
: Aggregate collectAggregateSelector (Comma collectAggregateSelector)*
|
|
;
|
|
|
|
collectAggregateSelector
|
|
: Identifier Assign functionCallExpression
|
|
;
|
|
|
|
collectGroupVariable
|
|
: Into collectSelector
|
|
| Into Identifier (Keep Identifier)?
|
|
;
|
|
|
|
collectCounter
|
|
: With Count Into Identifier
|
|
;
|
|
|
|
variableDeclaration
|
|
: Let Identifier Assign expression
|
|
| Let Identifier Assign OpenParen forExpression CloseParen
|
|
| Let Identifier Assign forTernaryExpression
|
|
;
|
|
|
|
param
|
|
: Param Identifier
|
|
;
|
|
|
|
variable
|
|
: Identifier
|
|
;
|
|
|
|
rangeOperator
|
|
: (integerLiteral | variable | param) Range (integerLiteral | variable | param)
|
|
;
|
|
|
|
arrayLiteral
|
|
: OpenBracket arrayElementList? CloseBracket
|
|
;
|
|
|
|
objectLiteral
|
|
: OpenBrace (propertyAssignment (Comma propertyAssignment)*)? Comma? CloseBrace
|
|
;
|
|
|
|
booleanLiteral
|
|
: BooleanLiteral
|
|
;
|
|
|
|
stringLiteral
|
|
: StringLiteral
|
|
| TemplateStringLiteral
|
|
;
|
|
|
|
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
|
|
| stringLiteral
|
|
;
|
|
|
|
expressionGroup
|
|
: OpenParen expression CloseParen
|
|
;
|
|
|
|
functionCallExpression
|
|
: Identifier arguments
|
|
;
|
|
|
|
arguments
|
|
: OpenParen(expression (Comma expression)*)?CloseParen
|
|
;
|
|
|
|
expression
|
|
: unaryOperator expression
|
|
| expression multiplicativeOperator expression
|
|
| expression additiveOperator expression
|
|
| functionCallExpression
|
|
| expressionGroup
|
|
| expression arrayOperator (inOperator | equalityOperator) expression
|
|
| expression inOperator expression
|
|
| expression equalityOperator expression
|
|
| expression logicalAndOperator expression
|
|
| expression logicalOrOperator expression
|
|
| expression QuestionMark expression? Colon expression
|
|
| rangeOperator
|
|
| stringLiteral
|
|
| integerLiteral
|
|
| floatLiteral
|
|
| booleanLiteral
|
|
| arrayLiteral
|
|
| objectLiteral
|
|
| variable
|
|
| memberExpression
|
|
| noneLiteral
|
|
| param
|
|
;
|
|
|
|
forTernaryExpression
|
|
: expression QuestionMark expression? Colon OpenParen forExpression CloseParen
|
|
| expression QuestionMark OpenParen forExpression CloseParen Colon expression
|
|
| expression QuestionMark OpenParen forExpression CloseParen Colon OpenParen forExpression CloseParen
|
|
;
|
|
|
|
arrayOperator
|
|
: All
|
|
| Any
|
|
| None
|
|
;
|
|
|
|
inOperator
|
|
: In
|
|
| Not In
|
|
;
|
|
|
|
equalityOperator
|
|
: Gt
|
|
| Lt
|
|
| Eq
|
|
| Gte
|
|
| Lte
|
|
| Neq
|
|
;
|
|
|
|
logicalAndOperator
|
|
: And
|
|
;
|
|
|
|
logicalOrOperator
|
|
: Or
|
|
;
|
|
|
|
multiplicativeOperator
|
|
: Multi
|
|
| Div
|
|
| Mod
|
|
;
|
|
|
|
additiveOperator
|
|
: Plus
|
|
| Minus
|
|
;
|
|
|
|
unaryOperator
|
|
: Not
|
|
| Plus
|
|
| Minus
|
|
| Like
|
|
; |