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

312 lines
5.3 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
;
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
| stringLiteral
2018-09-18 22:42:38 +02:00
;
expressionGroup
: OpenParen expression CloseParen
2018-09-18 22:42:38 +02:00
;
namespace
: (NamespaceSegment)*
;
2018-09-18 22:42:38 +02:00
functionCallExpression
: 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)*)*
;
memberExpression
2019-09-07 07:21:43 +02:00
: member memberPath
;
2018-09-18 22:42:38 +02:00
arguments
: OpenParen(expression (Comma expression)*)?CloseParen
;
expression
: unaryOperator expression
| expression multiplicativeOperator expression
| expression additiveOperator expression
2018-09-18 22:42:38 +02:00
| functionCallExpression
| expressionGroup
| expression arrayOperator (inOperator | equalityOperator) expression
| expression inOperator expression
| expression equalityOperator expression
| expression regexpOperator expression
| 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
;
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
;
regexpOperator
: RegexMatch
| RegexNotMatch
;
logicalAndOperator
2018-09-18 22:42:38 +02:00
: And
;
logicalOrOperator
: Or
;
multiplicativeOperator
: Multi
2018-09-18 22:42:38 +02:00
| Div
| Mod
;
additiveOperator
: Plus
| Minus
;
2018-09-18 22:42:38 +02:00
unaryOperator
: Not
| Plus
2018-09-18 22:42:38 +02:00
| Minus
| Like
;