topLevelObject
: declaration semis?
;
declaration (used by topLevelObject, classMemberDeclaration, statement)
: classDeclaration
| functionDeclaration
| propertyDeclaration
;
classDeclaration (used by declaration)
: 'class'
simpleIdentifier
classBody?
;
classBody (used by classDeclaration)
: '{' (declaration semis?)* '}'
;
functionValueParameters (used by functionDeclaration)
: '(' (functionValueParameter (',' functionValueParameter)* ','?)? ')'
;
functionValueParameter (used by functionValueParameters)
: parameter ('=' expression)?
;
parameter (used by functionValueParameter)
: simpleIdentifier ':' type
;
functionDeclaration (used by declaration)
: 'fun'
simpleIdentifier functionValueParameters
(':' type)?
functionBody
;
functionBody (used by functionDeclaration)
: block
| '=' expression
;
variableDeclaration (used by propertyDeclaration, forStatement)
: simpleIdentifier (':' type)?
;
propertyDeclaration (used by declaration)
: ('val' | 'var') variableDeclaration
('=' expression)? ';'?
;
type (used by functionDeclaration, variableDeclaration, parameter, parenthesizedType)
: (parenthesizedType | userType)
;
userType (used by type)
: simpleIdentifier ('.' simpleIdentifier)*
;
parenthesizedType (used by type)
: '(' type ')'
;
statements (used by block)
: (statement (semis statement)*)? semis?
;
statement (used by statements, controlStructureBody)
: (declaration | assignment | loopStatement | expression)
;
controlStructureBody (used by forStatement, whileStatement, doWhileStatement, ifExpression)
: block
| statement
;
block (used by functionBody, controlStructureBody)
: '{' statements '}'
;
loopStatement (used by statement)
: forStatement
| whileStatement
| doWhileStatement
;
forStatement (used by loopStatement)
: 'for'
'(' variableDeclaration 'in' expression ')'
controlStructureBody
;
whileStatement (used by loopStatement)
: 'while' '(' expression ')' (controlStructureBody | ';')
;
doWhileStatement (used by loopStatement)
: 'do' controlStructureBody 'while' '(' expression ')'
;
assignment (used by statement)
: directlyAssignableExpression assignmentAndOperator expression
;
semi
: (';' | NL) NL*
| EOF
;
semis
: (';' | NL)+
| EOF
;
expression (used by classParameter, functionValueParameter, functionBody, propertyDeclaration, statement, forStatement, whileStatement, doWhileStatement, assignment, indexingSuffix, valueArgument, parenthesizedExpression, lineStringExpression, multiLineStringExpression, ifExpression, rangeTest)
: disjunction
;
disjunction (used by expression)
: conjunction ('||' conjunction)*
;
conjunction (used by disjunction)
: equality ('&&' equality)*
;
equality (used by conjunction)
: comparison (equalityOperator comparison)*
;
comparison (used by equality)
: infixFunctionCall (comparisonOperator infixFunctionCall)*
;
infixOperation (used by comparison)
: infixFunctionCall (inOperator infixFunctionCall)*
;
infixFunctionCall (used by infixOperation)
: rangeExpression (simpleIdentifier rangeExpression)*
;
rangeExpression (used by infixFunctionCall)
: additiveExpression ('..' additiveExpression)*
;
additiveExpression (used by rangeExpression)
: multiplicativeExpression (additiveOperator multiplicativeExpression)*
;
multiplicativeExpression (used by additiveExpression)
: prefixUnaryExpression (multiplicativeOperator prefixUnaryExpression)*
;
prefixUnaryExpression (used by assignableExpression)
: prefixUnaryOperator* postfixUnaryExpression
;
postfixUnaryExpression (used by prefixUnaryExpression, directlyAssignableExpression)
: primaryExpression postfixUnarySuffix*
;
postfixUnarySuffix (used by postfixUnaryExpression)
: postfixUnaryOperator
| callSuffix
| indexingSuffix
| navigationSuffix
;
directlyAssignableExpression (used by assignment, parenthesizedDirectlyAssignableExpression)
: postfixUnaryExpression assignableSuffix
| simpleIdentifier
| parenthesizedDirectlyAssignableExpression
;
parenthesizedDirectlyAssignableExpression (used by directlyAssignableExpression)
: '(' directlyAssignableExpression ')'
;
assignableSuffix (used by directlyAssignableExpression)
: indexingSuffix
| navigationSuffix
;
indexingSuffix (used by postfixUnarySuffix, assignableSuffix)
: '[' expression (',' expression)* ','? ']'
;
navigationSuffix (used by postfixUnarySuffix, assignableSuffix)
: '.' simpleIdentifier
;
callSuffix (used by postfixUnarySuffix)
: '(' (expression (',' expression)* ','?)? ')'
;
primaryExpression (used by postfixUnaryExpression)
: parenthesizedExpression
| simpleIdentifier
| literalConstant
| stringLiteral
| ifExpression
| jumpExpression
;
parenthesizedExpression (used by navigationSuffix, primaryExpression)
: '(' expression ')'
;
literalConstant (used by primaryExpression)
: BooleanLiteral
| IntegerLiteral
| HexLiteral
| BinLiteral
| CharacterLiteral
| RealLiteral
| LongLiteral
| UnsignedLiteral
;
stringLiteral (used by primaryExpression)
: LineStringLiteral
| MultiLineStringLiteral
;
ifExpression (used by primaryExpression)
: 'if' '(' expression ')'
(controlStructureBody | (controlStructureBody? ';'? 'else' (controlStructureBody | ';')) | ';')
;
jumpExpression (used by primaryExpression)
: 'return' expression?
| 'continue'
| 'break'
;
assignmentAndOperator (used by assignment)
: '+='
| '-='
| '*='
| '/='
| '%='
;
equalityOperator (used by equality)
: '!='
| '!=='
| '=='
| '==='
;
comparisonOperator (used by comparison)
: '<'
| '>'
| '<='
| '>='
;
additiveOperator (used by additiveExpression)
: '+'
| '-'
;
multiplicativeOperator (used by multiplicativeExpression)
: '*'
| '/'
| '%'
;
prefixUnaryOperator (used by unaryPrefix)
: '++'
| '--'
| '-'
| '+'
| excl
;
postfixUnaryOperator (used by postfixUnarySuffix)
: '++'
| '--'
;
excl (used by prefixUnaryOperator, postfixUnaryOperator)
: '!'
| EXCL_WS
;
simpleIdentifier (used by classDeclaration, functionDeclaration, variableDeclaration, parameter, userType, infixFunctionCall, directlyAssignableExpression, navigationSuffix, valueArgument, primaryExpression, identifier)
: Identifier
identifier (used by packageHeader, importHeader)
: simpleIdentifier ('.' simpleIdentifier)*
;