Created
May 14, 2019 20:05
-
-
Save wolffcm/61498cd81e1140277bc0b4e9263766fd to your computer and use it in GitHub Desktop.
Flux grammar in ANTLR4 format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar Flux; | |
WS : [ \r\t\n]+ -> skip ; | |
IDENTIFIER : [a-zA-Z]+ ; | |
INT_LIT : [0-9]+ ; | |
FLOAT_LIT : [0-9]+ '.' [0-9]+ ; | |
STRING_LIT : '"' [a-zA-Z0-9]+ '"' ; | |
DURATION_LIT : [0-9][0-9][0-9][0-9] '-' [0-9][0-9] '-' [0-9][0-9] 'T' [0-9][0-9] ':' [0-9][0-9] ':' [0-9][0-9] 'Z' ; | |
PIPE_RECEIVE_LIT : '<-' ; | |
REGEX_LIT : '//' ; | |
file : packageClause? importList statementList? ; | |
packageClause : 'package' IDENTIFIER ; | |
importList : (importDeclaration)* ; | |
importDeclaration : 'import' IDENTIFIER STRING_LIT | |
| 'import' STRING_LIT ; | |
statementList : statement | |
| statementList statement ; | |
statement : optionAssignment | |
| builtinStatement | |
| testStatement | |
| identStatement | |
| returnStatement | |
| expressionStatement ; | |
identStatement : IDENTIFIER assignStatement | |
| IDENTIFIER expressionSuffix ; | |
optionAssignment : 'option' IDENTIFIER optionAssignmentSuffix ; | |
optionAssignmentSuffix : assignStatement | |
| '.' IDENTIFIER assignStatement ; | |
builtinStatement : 'builtin' IDENTIFIER ; | |
testStatement : 'test' IDENTIFIER assignStatement ; | |
assignStatement : '=' expression ; | |
returnStatement : 'return' expression ; | |
expressionStatement : expression ; | |
expression : conditionalExpression ; | |
conditionalExpression : logicalOrExpression | |
| 'if' expression 'then' expression 'else' expression ; | |
expressionSuffix : (postfixOperator)* (pipeExpressionSuffix)* (multiplicativeExpressionSuffix)* (additiveExpressionSuffix)* (comparisonExpressionSuffix)* (logicalAndExpressionSuffix)* (logicalOrExpressionSuffix)* ; | |
logicalOrExpression : logicalAndExpression (logicalOrExpressionSuffix)* ; | |
logicalOrExpressionSuffix : logicalOrOperator logicalAndExpression ; | |
logicalOrOperator : 'or' ; | |
logicalAndExpression : unaryLogicalExpression (logicalAndExpressionSuffix)* ; | |
logicalAndExpressionSuffix : logicalAndOperator unaryLogicalExpression ; | |
logicalAndOperator : 'and' ; | |
unaryLogicalExpression : comparisonExpression | |
| unaryLogicalOperator unaryLogicalExpression ; | |
unaryLogicalOperator : 'not' ; | |
comparisonExpression : additiveExpression (comparisonExpressionSuffix)* ; | |
comparisonExpressionSuffix : comparisonOperator additiveExpression ; | |
comparisonOperator : '==' | '!=' | '<' | '<=' | '>' | '>=' | '=~' | '!~' ; | |
additiveExpression : multiplicativeExpression (additiveExpressionSuffix)* ; | |
additiveExpressionSuffix : additiveOperator multiplicativeExpression ; | |
additiveOperator : '+' | '-' ; | |
multiplicativeExpression : pipeExpression (multiplicativeExpressionSuffix)* ; | |
multiplicativeExpressionSuffix : multiplicativeOperator pipeExpression ; | |
multiplicativeOperator : '*'| '/'; | |
pipeExpression : unaryExpression (pipeExpressionSuffix)* ; | |
pipeExpressionSuffix : pipeOperator unaryExpression ; | |
pipeOperator : '|>' ; | |
unaryExpression : postfixExpression | |
| prefixOperator unaryExpression ; | |
prefixOperator : '+' | '-' ; | |
postfixExpression : primaryExpression (postfixOperator)* ; | |
postfixOperator : memberExpression | |
| callExpression | |
| indexExpression ; | |
memberExpression : dotExpression | |
| memberBracketExpression ; | |
dotExpression : '.' IDENTIFIER ; | |
memberBracketExpression : '[' STRING_LIT ']' ; | |
callExpression : '(' propertyList ')' ; | |
indexExpression : '[' expression ']' ; | |
primaryExpression : IDENTIFIER | |
| INT_LIT | |
| FLOAT_LIT | |
| STRING_LIT | |
| REGEX_LIT | |
| DURATION_LIT | |
| PIPE_RECEIVE_LIT | |
| objectLiteral | |
| arrayLiteral | |
| parenExpression ; | |
objectLiteral : '{' propertyList '}' ; | |
arrayLiteral : '[' expressionList ']' ; | |
parenExpression : '(' parenExpressionBody ; | |
parenExpressionBody : ')' functionExpressionSuffix | |
| IDENTIFIER parenIdentExpression | |
| expression ')' ; | |
parenIdentExpression : ')' (functionExpressionSuffix)? | |
| '=' expression ( ',' parameterList )? ')' functionExpressionSuffix | |
| ',' parameterList ')' functionExpressionSuffix | |
| expressionSuffix ')' ; | |
functionExpressionSuffix : '=>' functionBodyExpression ; | |
functionBodyExpression : block | |
| expression ; | |
block : '{' statementList '}' ; | |
expressionList : ( expression ( ',' expression )* )? ; | |
propertyList : ( property ( ',' property )* )? ; | |
property : IDENTIFIER ( ':' expression )? | |
| STRING_LIT ':' expression ; | |
parameterList : parameter | |
| parameterList ',' parameter ; | |
parameter : IDENTIFIER ( '=' expression )? ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment