Grammar
- omitted lexical modes.
Short description:
- operator denotes alternative,
- operator
*
denotes iteration (zero or more), - operator
+
denotes iteration (one or more), - operator
?
denotes option (zero or one), - operator
..
denotes range (from left to right), - operator
~
denotes negation.
Grammar source files
Kotlin grammar source files (in ANTLR format) are located in the :
- KotlinLexer.g4 describes ;
- UnicodeClasses.g4 describes the characters that can be used in identifiers (these rules are omitted on this page for better readability);
- describes syntax.
The grammar on this page corresponds to the grammar files above.
Symbols and naming
Terminal symbol names start with an uppercase letter, e.g. Identifier.
Non-terminal symbol names start with a lowercase letter, e.g. .
Symbol definitions may be documented with attributes:
start
attribute denotes a symbol that represents the whole source file (see kotlinFile and ),helper
attribute denotes a lexer fragment rule (used only inside other terminal symbols).
Also for better readability some simplifications are made:
- lexer rules consisting of one string literal element are inlined to the use site,
- new line tokens are excluded (new lines are not allowed in some places, see source grammar files for details).
Scope
The grammar corresponds to the latest stable version of the Kotlin compiler excluding lexer and parser rules for experimental features that are disabled by default.
General
Relevant pages: Packages
start
kotlinFile
: ? fileAnnotation* importList * EOF
;
start
script
: shebangLine? * packageHeader (statement )* EOF
;
shebangLine
(used by kotlinFile, )
: ShebangLine
;
fileAnnotation
(used by , script)
: (‘@’ | ) ‘file’ ‘:’ ((‘[‘ unescapedAnnotation+ ‘]‘) | )
;
See Packages
packageHeader
(used by , script)
: (‘package’ semi?)?
;
See
importList
(used by kotlinFile, )
: importHeader*
;
importHeader
(used by )
: ‘import’ identifier ((‘.’ ‘*‘) | )? semi?
;
importAlias
(used by )
: ‘as’ simpleIdentifier
;
topLevelObject
(used by )
: declaration ?
;
typeAlias
(used by declaration)
: ? ‘typealias’ simpleIdentifier ? ‘=’ type
;
declaration
(used by , classMemberDeclaration, )
: classDeclaration
|
| functionDeclaration
|
| typeAlias
;
Classes
classDeclaration
(used by )
: modifiers? (‘class’ | (‘fun’? ‘interface’))
typeParameters?
?
(‘:’ delegationSpecifiers)?
?
(classBody | )?
;
primaryConstructor
(used by classDeclaration)
: (? ‘constructor’)? classParameters
;
classBody
(used by , companionObject, , enumEntry, )
: ‘{‘ classMemberDeclarations ‘}’
;
classParameters
(used by )
: ‘(‘ (classParameter (‘,’ )* ‘,’?)? ‘)’
;
classParameter
(used by classParameters)
: ? (‘val’ | ‘var’)? simpleIdentifier ‘:’ (‘=’ expression)?
;
delegationSpecifiers
(used by , companionObject, , objectLiteral)
: (‘,’ annotatedDelegationSpecifier)*
;
delegationSpecifier
(used by )
: constructorInvocation
|
| userType
|
;
constructorInvocation
(used by delegationSpecifier, )
: userType
;
annotatedDelegationSpecifier
(used by delegationSpecifiers)
: * delegationSpecifier
;
explicitDelegation
(used by )
: (userType | ) ‘by’ expression
;
See
typeParameters
(used by typeAlias, , functionDeclaration, )
: ‘<’ typeParameter (‘,’ )* ‘,’? ‘>’
;
typeParameter
(used by typeParameters)
: ? simpleIdentifier (‘:’ )?
;
typeConstraints
(used by , functionDeclaration, , anonymousFunction)
: ‘where’ (‘,’ typeConstraint)*
;
typeConstraint
(used by )
: annotation* ‘:’ type
;
Class members
classMemberDeclarations
(used by classBody, )
: (classMemberDeclaration ?)*
;
classMemberDeclaration
(used by classMemberDeclarations)
:
| companionObject
|
| secondaryConstructor
;
anonymousInitializer
(used by )
: ‘init’ block
;
companionObject
(used by )
: modifiers? ‘companion’ ‘object’ ?
(‘:’ delegationSpecifiers)?
?
;
functionValueParameters
(used by functionDeclaration, )
: ‘(‘ (functionValueParameter (‘,’ )* ‘,’?)? ‘)’
;
functionValueParameter
(used by functionValueParameters)
: ? parameter (‘=’ )?
;
functionDeclaration
(used by declaration)
: ? ‘fun’ typeParameters?
( ‘.’)?
simpleIdentifier
(‘:’ type)? ?
functionBody?
;
functionBody
(used by , getter, , anonymousFunction)
:
| ‘=’ expression
;
variableDeclaration
(used by , propertyDeclaration, , lambdaParameter, )
: annotation* (‘:’ type)?
;
multiVariableDeclaration
(used by , forStatement, )
: ‘(‘ variableDeclaration (‘,’ )* ‘,’? ‘)’
;
propertyDeclaration
(used by )
: modifiers? (‘val’ | ‘var’) ?
(receiverType ‘.’)?
( | variableDeclaration)
?
((‘=’ expression) | )? ‘;’?
((getter? (? setter)?) | (? (semi? )?))
;
propertyDelegate
(used by propertyDeclaration)
: ‘by’
;
getter
(used by propertyDeclaration)
: ? ‘get’
| modifiers? ‘get’ ‘(‘ ‘)’
(‘:’ )?
functionBody
;
setter
(used by )
: modifiers? ‘set’
| ? ‘set’ ‘(‘ parameterWithOptionalType ‘,’? ‘)’
(‘:’ )?
functionBody
;
parametersWithOptionalType
(used by )
: ‘(‘
(parameterWithOptionalType (‘,’ )* ‘,’?)? ‘)’
;
parameterWithOptionalType
(used by setter, )
: parameterModifiers? (‘:’ type)?
;
parameter
(used by , functionTypeParameters)
: ‘:’ type
;
See
objectDeclaration
(used by declaration)
: ? ‘object’ simpleIdentifier (‘:’ )? classBody?
;
secondaryConstructor
(used by )
: modifiers? ‘constructor’
(‘:’ constructorDelegationCall)? ?
;
constructorDelegationCall
(used by secondaryConstructor)
: ‘this’
| ‘super’ valueArguments
;
See
enumClassBody
(used by classDeclaration)
: ‘{‘ ? (‘;’ classMemberDeclarations)? ‘}’
;
enumEntries
(used by )
: enumEntry (‘,’ )* ‘,’?
;
enumEntry
(used by enumEntries)
: ? simpleIdentifier ? classBody?
;
Types
See Types
type
(used by , classParameter, , typeConstraint, , variableDeclaration, , setter, , parameter, , functionType, , parenthesizedType, , asExpression, , anonymousFunction, , typeTest, )
: typeModifiers? ( | nullableType | | functionType)
;
typeReference
(used by , nullableType, )
: userType
| ‘dynamic’
;
nullableType
(used by , receiverType)
: ( | parenthesizedType) +
;
quest
(used by nullableType)
: ‘?’
|
;
userType
(used by delegationSpecifier, , explicitDelegation, , parenthesizedUserType, )
: simpleUserType (‘.’ )*
;
simpleUserType
(used by userType)
: typeArguments?
;
typeProjection
(used by )
: typeProjectionModifiers?
| ‘*‘
;
typeProjectionModifiers
(used by typeProjection)
: +
;
typeProjectionModifier
(used by typeProjectionModifiers)
:
| annotation
;
functionType
(used by , explicitDelegation, )
: (receiverType ‘.’)? ‘->’ type
;
functionTypeParameters
(used by )
: ‘(‘ (parameter | )? (‘,’ (parameter | ))* ‘,’? ‘)’
;
parenthesizedType
(used by type, , receiverType)
: ‘(‘ ‘)’
;
receiverType
(used by functionDeclaration, , functionType, )
: typeModifiers? ( | nullableType | )
;
parenthesizedUserType
(used by parenthesizedUserType)
: ‘(‘ ‘)’
| ‘(‘ parenthesizedUserType ‘)’
;
Statements
statements
(used by block, )
: (statement ( statement)*)? ?
;
statement
(used by script, , controlStructureBody)
: ( | annotation)* ( | assignment | | expression)
;
See
label
(used by statement, , annotatedLambda)
: (‘@’ | AT_POST_WS)
;
controlStructureBody
(used by , whileStatement, , ifExpression, )
: block
|
;
block
(used by anonymousInitializer, , secondaryConstructor, , tryExpression, , finallyBlock)
: ‘{‘ ‘}’
;
loopStatement
(used by statement)
:
| whileStatement
|
;
forStatement
(used by loopStatement)
: ‘for’
‘(‘ * (variableDeclaration | ) ‘in’ expression ‘)’
?
;
whileStatement
(used by loopStatement)
: ‘while’ ‘(‘ ‘)’ controlStructureBody
| ‘while’ ‘(‘ ‘)’ ‘;’
;
doWhileStatement
(used by loopStatement)
: ‘do’ ? ‘while’ ‘(‘ expression ‘)’
;
assignment
(used by )
: directlyAssignableExpression ‘=’
| assignableExpression expression
;
semi
(used by , packageHeader, , propertyDeclaration, )
: EOF
;
semis
(used by topLevelObject, , statements)
Expressions
expression
(used by classParameter, , functionValueParameter, , propertyDeclaration, , statement, , whileStatement, , assignment, , valueArgument, , collectionLiteral, , multiLineStringExpression, , whenSubject, , rangeTest, )
: disjunction
;
disjunction
(used by )
: conjunction (‘||’ )*
;
conjunction
(used by disjunction)
: (‘&&’ equality)*
;
equality
(used by )
: comparison ( comparison)*
;
comparison
(used by )
: genericCallLikeComparison ( genericCallLikeComparison)*
;
genericCallLikeComparison
(used by )
: infixOperation *
;
infixOperation
(used by genericCallLikeComparison)
: ((inOperator ) | (isOperator ))*
;
elvisExpression
(used by infixOperation)
: (elvis )*
;
elvis
(used by elvisExpression)
: ‘?’ ‘:’
;
infixFunctionCall
(used by )
: rangeExpression ( rangeExpression)*
;
rangeExpression
(used by )
: additiveExpression (‘..’ )*
;
additiveExpression
(used by rangeExpression)
: (additiveOperator )*
;
multiplicativeExpression
(used by additiveExpression)
: (multiplicativeOperator )*
;
asExpression
(used by multiplicativeExpression)
: (asOperator )*
;
prefixUnaryExpression
(used by asExpression, )
: unaryPrefix*
;
unaryPrefix
(used by prefixUnaryExpression)
:
| label
|
;
postfixUnaryExpression
(used by prefixUnaryExpression, )
: primaryExpression
| postfixUnarySuffix+
;
postfixUnarySuffix
(used by )
: postfixUnaryOperator
|
| callSuffix
|
| navigationSuffix
;
directlyAssignableExpression
(used by , parenthesizedDirectlyAssignableExpression)
: assignableSuffix
|
| parenthesizedDirectlyAssignableExpression
;
parenthesizedDirectlyAssignableExpression
(used by )
: ‘(‘ directlyAssignableExpression ‘)’
;
assignableExpression
(used by , parenthesizedAssignableExpression)
:
| parenthesizedAssignableExpression
;
parenthesizedAssignableExpression
(used by )
: ‘(‘ assignableExpression ‘)’
;
assignableSuffix
(used by )
: typeArguments
|
| navigationSuffix
;
indexingSuffix
(used by , assignableSuffix)
: ‘[‘ (‘,’ expression)* ‘,’? ‘]‘
;
navigationSuffix
(used by , assignableSuffix)
: (simpleIdentifier | | ‘class’)
;
callSuffix
(used by genericCallLikeComparison, )
: typeArguments? ? annotatedLambda
| ? valueArguments
;
annotatedLambda
(used by )
: annotation* ? lambdaLiteral
;
typeArguments
(used by , postfixUnarySuffix, , callSuffix)
: ‘<’ (‘,’ typeProjection)* ‘,’? ‘>’
;
valueArguments
(used by , constructorDelegationCall, , callSuffix)
: ‘(‘ ‘)’
| ‘(‘ (‘,’ valueArgument)* ‘,’? ‘)’
;
valueArgument
(used by )
: annotation? ( ‘=’)? ‘*‘? expression
;
primaryExpression
(used by )
: parenthesizedExpression
|
| literalConstant
|
| callableReference
|
| objectLiteral
|
| thisExpression
|
| ifExpression
|
| tryExpression
|
;
parenthesizedExpression
(used by navigationSuffix, )
: ‘(‘ expression ‘)’
;
collectionLiteral
(used by )
: ‘[‘ expression (‘,’ )* ‘,’? ‘]‘
| ‘[‘ ‘]‘
;
literalConstant
(used by primaryExpression)
:
| IntegerLiteral
|
| BinLiteral
|
| RealLiteral
| ‘null’
|
| UnsignedLiteral
;
stringLiteral
(used by )
: lineStringLiteral
|
;
lineStringLiteral
(used by stringLiteral)
: ‘“‘ ( | lineStringExpression)* ‘“‘
;
multiLineStringLiteral
(used by )
: ‘“””‘ (multiLineStringContent | | ‘“‘)*
TRIPLE_QUOTE_CLOSE
;
lineStringContent
(used by )
: LineStrText
|
| LineStrRef
;
lineStringExpression
(used by )
: ‘${‘ expression ‘}’
;
multiLineStringContent
(used by )
: MultiLineStrText
| ‘“‘
|
;
multiLineStringExpression
(used by multiLineStringLiteral)
: ‘${‘ ‘}’
;
lambdaLiteral
(used by annotatedLambda, )
: ‘{‘ statements ‘}’
| ‘{‘ ? ‘->’ statements ‘}’
;
lambdaParameters
(used by )
: lambdaParameter (‘,’ )* ‘,’?
;
lambdaParameter
(used by lambdaParameters)
:
| multiVariableDeclaration (‘:’ )?
;
anonymousFunction
(used by functionLiteral)
: ‘fun’ ( ‘.’)? parametersWithOptionalType
(‘:’ )? typeConstraints?
?
;
functionLiteral
(used by primaryExpression)
:
| anonymousFunction
;
objectLiteral
(used by )
: ‘object’ ‘:’ delegationSpecifiers
| ‘object’ classBody
;
thisExpression
(used by )
: ‘this’
| THIS_AT
;
superExpression
(used by )
: ‘super’ (‘<’ type ‘>’)? (‘@’ )?
| SUPER_AT
;
ifExpression
(used by )
: ‘if’ ‘(‘ expression ‘)’
( | ‘;’)
| ‘if’ ‘(‘ expression ‘)’
? ‘;’? ‘else’ (controlStructureBody | ‘;’)
;
whenSubject
(used by )
: ‘(‘ (annotation* ‘val’ ‘=’)? expression ‘)’
;
whenExpression
(used by )
: ‘when’ whenSubject? ‘{‘ * ‘}’
;
whenEntry
(used by whenExpression)
: (‘,’ whenCondition)* ‘,’? ‘->’ semi?
| ‘else’ ‘->’ semi?
;
whenCondition
(used by )
: expression
|
| typeTest
;
rangeTest
(used by )
: inOperator
;
typeTest
(used by whenCondition)
: type
;
tryExpression
(used by )
: ‘try’ block ((+ finallyBlock?) | )
;
catchBlock
(used by tryExpression)
: ‘catch’ ‘(‘ * simpleIdentifier ‘:’ ‘,’? ‘)’ block
;
finallyBlock
(used by )
: ‘finally’ block
;
jumpExpression
(used by )
: ‘throw’ expression
| (‘return’ | ) expression?
| ‘continue’
|
| ‘break’
| BREAK_AT
;
callableReference
(used by )
: (receiverType? ‘::’ ( | ‘class’))
;
assignmentAndOperator
(used by assignment)
: ‘+=’
| ‘-=’
| ‘*=’
| ‘/=’
| ‘%=’
;
equalityOperator
(used by )
: ‘!=’
| ‘!==’
| ‘==’
| ‘===’
;
comparisonOperator
(used by comparison)
: ‘<’
| ‘>’
| ‘<=’
| ‘>=’
;
inOperator
(used by , rangeTest)
: ‘in’
|
;
isOperator
(used by infixOperation, )
: ‘is’
| NOT_IS
;
additiveOperator
(used by )
: ‘+’
| ‘-‘
;
multiplicativeOperator
(used by multiplicativeExpression)
: ‘*‘
| ‘/‘
| ‘%’
;
asOperator
(used by )
: ‘as’
| ‘as?’
;
prefixUnaryOperator
(used by unaryPrefix)
: ‘++’
| ‘—‘
| ‘-‘
| ‘+’
|
;
postfixUnaryOperator
(used by postfixUnarySuffix)
: ‘++’
| ‘—‘
| ‘!’
;
excl
(used by prefixUnaryOperator, )
: ‘!’
| EXCL_WS
;
memberAccessOperator
(used by )
: ‘.’
| safeNav
| ‘::’
;
safeNav
(used by )
: ‘?’ ‘.’
;
Modifiers
modifiers
(used by , classDeclaration, , classParameter, , functionDeclaration, , getter, , objectDeclaration, , enumEntry)
:
| modifier+
;
parameterModifiers
(used by , parameterWithOptionalType)
:
| parameterModifier+
;
modifier
(used by )
: classModifier
|
| visibilityModifier
|
| propertyModifier
|
| parameterModifier
|
;
typeModifiers
(used by type, )
: typeModifier+
;
typeModifier
(used by )
: annotation
| ‘suspend’
;
classModifier
(used by )
memberModifier
(used by modifier)
: ‘override’
| ‘lateinit’
;
visibilityModifier
(used by )
: ‘public’
| ‘private’
| ‘internal’
| ‘protected’
;
varianceModifier
(used by typeProjectionModifier, )
: ‘in’
| ‘out’
;
typeParameterModifiers
(used by typeParameter)
: +
;
typeParameterModifier
(used by typeParameterModifiers)
:
| varianceModifier
|
;
functionModifier
(used by modifier)
: ‘tailrec’
| ‘operator’
| ‘infix’
| ‘inline’
| ‘external’
| ‘suspend’
;
propertyModifier
(used by )
: ‘const’
;
inheritanceModifier
(used by modifier)
: ‘abstract’
| ‘final’
| ‘open’
;
parameterModifier
(used by , modifier)
: ‘vararg’
| ‘noinline’
| ‘crossinline’
;
reificationModifier
(used by )
: ‘reified’
;
platformModifier
(used by modifier)
: ‘expect’
| ‘actual’
;
Annotations
annotation
(used by annotatedDelegationSpecifier, , variableDeclaration, , statement, , unaryPrefix, , valueArgument, , catchBlock, , parameterModifiers, , typeParameterModifier)
:
| multiAnnotation
;
singleAnnotation
(used by )
: annotationUseSiteTarget
| (‘@’ | AT_PRE_WS)
;
multiAnnotation
(used by annotation)
: ‘[‘ unescapedAnnotation+ ‘]‘
| (‘@’ | ) ‘[‘ unescapedAnnotation+ ‘]‘
;
annotationUseSiteTarget
(used by , multiAnnotation)
: (‘@’ | )
(‘field’ | ‘property’ | ‘get’ | ‘set’ | ‘receiver’ | ‘param’ | ‘setparam’ | ‘delegate’) ‘:’
;
unescapedAnnotation
(used by fileAnnotation, , multiAnnotation)
:
| userType
;
Identifiers
simpleIdentifier
(used by importAlias, , classDeclaration, , typeParameter, , companionObject, , variableDeclaration, , parameter, , enumEntry, , label, , directlyAssignableExpression, , valueArgument, , superExpression, , callableReference, )
: Identifier
| ‘abstract’
| ‘annotation’
| ‘by’
| ‘catch’
| ‘companion’
| ‘constructor’
| ‘crossinline’
| ‘data’
| ‘dynamic’
| ‘enum’
| ‘external’
| ‘final’
| ‘finally’
| ‘get’
| ‘import’
| ‘infix’
| ‘init’
| ‘inline’
| ‘inner’
| ‘internal’
| ‘lateinit’
| ‘noinline’
| ‘open’
| ‘operator’
| ‘out’
| ‘override’
| ‘private’
| ‘protected’
| ‘public’
| ‘reified’
| ‘sealed’
| ‘tailrec’
| ‘set’
| ‘vararg’
| ‘where’
| ‘field’
| ‘property’
| ‘receiver’
| ‘param’
| ‘setparam’
| ‘delegate’
| ‘file’
| ‘expect’
| ‘actual’
| ‘const’
| ‘suspend’
;
identifier
(used by , importHeader)
: (‘.’ simpleIdentifier)*
;
ShebangLine
(used by )
: ‘#!’ ~[\r\n]*
;
DelimitedComment
(used by DelimitedComment, )
: (‘/*‘ (DelimitedComment | .)*? ‘*/‘)
;
LineComment
(used by )
: (‘//‘ ~[\r\n]*)
;
WS
(used by Hidden)
: [\u0020\u0009\u000C]
;
helper
Hidden
(used by , AT_POST_WS, , AT_BOTH_WS, , NOT_IS, )
: DelimitedComment
|
| WS
;
Separators and operations
RESERVED
: ‘…’
;
EXCL_WS
(used by excl)
: ‘!’
;
DOUBLE_ARROW
: ‘=>’
;
DOUBLE_SEMICOLON
: ‘;;’
;
HASH
: ‘#’
;
AT_POST_WS
(used by label)
: ‘@’
;
AT_PRE_WS
(used by fileAnnotation, , multiAnnotation, )
: Hidden ‘@’
;
AT_BOTH_WS
: ‘@’ Hidden
;
QUEST_WS
(used by )
: ‘?’ Hidden
;
SINGLE_QUOTE
: ‘\‘’
;
Keywords
RETURN_AT
(used by jumpExpression)
: ‘return@’
;
CONTINUE_AT
(used by jumpExpression)
: ‘continue@’
;
BREAK_AT
(used by jumpExpression)
: ‘break@’
;
THIS_AT
(used by thisExpression)
: ‘this@’
;
SUPER_AT
(used by superExpression)
: ‘super@’
;
TYPEOF
: ‘typeof’
;
NOT_IS
(used by isOperator)
: ‘!is’
;
NOT_IN
(used by inOperator)
: ‘!in’
;
Literals
helper
DecDigit
(used by , DecDigits, )
: ‘0’..’9’
;
helper
DecDigitNoZero
(used by IntegerLiteral)
: ‘1’..’9’
;
helper
DecDigitOrSeparator
(used by , IntegerLiteral)
:
| ‘_‘
;
helper
DecDigits
(used by DoubleExponent, , DoubleLiteral)
: DecDigitOrSeparator*
| DecDigit
;
helper
DoubleExponent
(used by )
: [eE] [+-]? DecDigits
;
RealLiteral
(used by )
: FloatLiteral
|
;
FloatLiteral
(used by RealLiteral)
: [fF]
| DecDigits [fF]
;
DoubleLiteral
(used by , FloatLiteral)
: ? ‘.’ DecDigits ?
| DecDigits
;
IntegerLiteral
(used by literalConstant, , LongLiteral)
: DecDigitOrSeparator*
| DecDigit
;
helper
HexDigit
(used by , HexLiteral, )
: [0-9a-fA-F]
;
helper
HexDigitOrSeparator
(used by HexLiteral)
:
| ‘_‘
;
HexLiteral
(used by literalConstant, , LongLiteral)
: ‘0’ [xX] HexDigitOrSeparator*
| ‘0’ [xX] HexDigit
;
helper
BinDigit
(used by , BinLiteral)
: [01]
;
helper
BinDigitOrSeparator
(used by )
: BinDigit
| ‘_‘
;
BinLiteral
(used by , UnsignedLiteral, )
: ‘0’ [bB] BinDigit * BinDigit
| ‘0’ [bB]
;
UnsignedLiteral
(used by literalConstant)
: ( | HexLiteral | ) [uU] [lL]?
;
LongLiteral
(used by literalConstant)
: ( | HexLiteral | ) [lL]
;
BooleanLiteral
(used by literalConstant)
: ‘true’
| ‘false’
;
CharacterLiteral
(used by )
: ‘\‘’ (EscapeSeq | ~[\n\r’\\]) ‘\‘’
;
Identifiers
helper
UnicodeDigit
(used by Identifier)
:
;
Identifier
(used by simpleIdentifier, , CONTINUE_AT, , THIS_AT, , IdentifierOrSoftKey)
: ( | ‘_‘) (Letter | ‘_‘ | )*
| ‘`‘ ~([\r\n] | ‘`‘)+ ‘`‘
;
Depending on the target and publicity of the declaration, the set of allowed symbols in identifiers is different. This rule contains the union of allowed symbols from all targets. Thus, the code for any target can be parsed using the grammar.
The allowed symbols in identifiers corresponding to the target and publicity of the declaration are given below.
Kotlin/JVM (any declaration publicity)
~ ( [\r\n] | ‘`‘ | ‘.’ | ‘;’ | ‘:’ | ‘\‘ | ‘/‘ | ‘[‘ | ‘]‘ | ‘<’ | ‘>’ )
Kotlin/Android (any declaration publicity)
The allowed symbols are different from allowed symbols for Kotlin/JVM and correspond to the Dalvik Executable format.
Kotlin/JS (private declarations)
~ ( [\r\n] | ‘`‘ )
Kotlin/JS (public declarations)
The allowed symbols for public declarations correspond to the except that ECMA reserved words is allowed.
Kotlin/Native (any declaration publicity)
~ ( [\r\n] | ‘`‘ )
IdentifierOrSoftKey
(used by )
: Identifier
| ‘abstract’
| ‘annotation’
| ‘by’
| ‘catch’
| ‘companion’
| ‘constructor’
| ‘crossinline’
| ‘data’
| ‘dynamic’
| ‘enum’
| ‘external’
| ‘final’
| ‘finally’
| ‘import’
| ‘infix’
| ‘init’
| ‘inline’
| ‘inner’
| ‘internal’
| ‘lateinit’
| ‘noinline’
| ‘open’
| ‘operator’
| ‘out’
| ‘override’
| ‘private’
| ‘protected’
| ‘public’
| ‘reified’
| ‘sealed’
| ‘tailrec’
| ‘vararg’
| ‘where’
| ‘get’
| ‘set’
| ‘field’
| ‘property’
| ‘receiver’
| ‘param’
| ‘setparam’
| ‘delegate’
| ‘file’
| ‘expect’
| ‘actual’
| ‘const’
| ‘suspend’
;
FieldIdentifier
(used by , MultiLineStrRef)
: ‘$’
;
helper
UniCharacterLiteral
(used by EscapeSeq, )
: ‘\\‘ ‘u’ HexDigit HexDigit
;
helper
EscapedIdentifier
(used by EscapeSeq, )
: ‘\\‘ (‘t’ | ‘b’ | ‘r’ | ‘n’ | ‘\‘’ | ‘“‘ | ‘\\‘ | ‘$’)
;
helper
EscapeSeq
(used by CharacterLiteral)
:
| EscapedIdentifier
;
Characters
helper
Letter
(used by Identifier)
:
| UNICODE_CLASS_LM
|
| UNICODE_CLASS_LT
|
| UNICODE_CLASS_NL
;
Strings
LineStrRef
(used by lineStringContent)
:
;
See String templates
LineStrText
(used by )
: ~(‘\\‘ | ‘“‘ | ‘$’)+
| ‘$’
;
LineStrEscapedChar
(used by lineStringContent)
:
| UniCharacterLiteral
;
TRIPLE_QUOTE_CLOSE
(used by )
: (‘“‘? ‘“””‘)
;
MultiLineStrRef
(used by multiLineStringContent)
:
;
MultiLineStrText
(used by multiLineStringContent)
: ~(‘“‘ | ‘$’)+
| ‘$’
;
ErrorCharacter