1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/parser/antlr/FqlParser.g4

269 lines
4.8 KiB
Plaintext
Raw Normal View History

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
| Return forTernaryExpression
2018-09-18 22:42:38 +02:00
;
forExpression
: For forExpressionValueVariable (Comma forExpressionKeyVariable)? In forExpressionSource
(forExpressionClause)*
(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
;
filterClause
: Filter expression
;
limitClause
: Limit IntegerLiteral (Comma IntegerLiteral)?
;
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
: Collect collectVariable Assign expression
| Collect collectVariable Assign expression Into collectGroupVariable
| Collect collectVariable Assign expression Into collectGroupVariable Keep collectKeepVariable
| Collect collectVariable Assign expression With Count collectCountVariable
| Collect collectVariable Assign expression Aggregate collectAggregateVariable Assign collectAggregateExpression
| Collect Aggregate collectAggregateVariable Assign collectAggregateExpression
| Collect With Count Into collectCountVariable
;
collectVariable
: Identifier
;
collectGroupVariable
: Identifier
;
collectKeepVariable
: Identifier
;
collectCountVariable
: Identifier
;
collectAggregateVariable
: Identifier
;
collectAggregateExpression
: expression
;
collectOption
:
;
forExpressionBody
: variableDeclaration
| functionCallExpression
;
forExpressionReturn
: returnExpression
| forExpression
;
variableDeclaration
: Let Identifier Assign expression
| Let Identifier Assign OpenParen forExpression CloseParen
| 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
;
memberExpression
: Identifier (Dot propertyName (computedPropertyName)*)+
| Identifier computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
;
shorthandPropertyName
: variable
;
computedPropertyName
: OpenBracket expression CloseBracket
;
propertyName
: Identifier
;
expressionSequence
: expression (Comma expression)*
;
functionCallExpression
: Identifier arguments
;
arguments
: OpenParen(expression (Comma expression)*)?CloseParen
;
expression
: expression equalityOperator expression
| expression logicalOperator expression
| expression mathOperator expression
| functionCallExpression
| OpenParen expressionSequence CloseParen
| Plus expression
| Minus expression
2018-09-23 03:06:19 +02:00
| expression (Not)? In expression
2018-09-18 22:42:38 +02:00
| Not 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
;
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-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
| Plus
2018-09-18 22:42:38 +02:00
| Minus
| Like
;