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

285 lines
4.9 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
(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
: 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
: Collect collectCounter
| Collect collectAggregator
| Collect collectGrouping collectAggregator
| Collect collectGrouping collectGroupVariable
| Collect collectGrouping collectCounter
| Collect collectGrouping
2018-09-18 22:42:38 +02:00
;
collectSelector
: Identifier Assign expression
2018-09-18 22:42:38 +02:00
;
collectGrouping
: collectSelector (Comma collectSelector)*
2018-09-18 22:42:38 +02:00
;
collectAggregator
: Aggregate collectAggregateSelector (Comma collectAggregateSelector)*
2018-09-18 22:42:38 +02:00
;
collectAggregateSelector
: Identifier Assign functionCallExpression
2018-09-18 22:42:38 +02:00
;
collectGroupVariable
: Into collectSelector
| Into Identifier (Keep Identifier)?
2018-09-18 22:42:38 +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
| 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
| 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
| stringLiteral
2018-09-18 22:42:38 +02:00
;
expressionSequence
: expression (Comma expression)*
;
functionCallExpression
: Identifier arguments
;
arguments
: OpenParen(expression (Comma expression)*)?CloseParen
;
expression
: unaryOperator expression
| expression equalityOperator expression
2018-09-18 22:42:38 +02:00
| expression logicalOperator expression
| expression mathOperator expression
| functionCallExpression
| OpenParen expressionSequence CloseParen
| 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
;
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
;
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
;