xref: /Universal-ctags/peg/kotlin.peg (revision b7514e1ec672a8580bea041544e9259a169f09c3)
1d532b5c4SJan Dolinár# Copyright (c) 2021 Jan Dolinár
2d532b5c4SJan Dolinár#
3d532b5c4SJan Dolinár# This source code is released for free distribution under the terms of the
4d532b5c4SJan Dolinár# GNU General Public License version 2.
5d532b5c4SJan Dolinár#
6d532b5c4SJan Dolinár# This file contains description of Kotlin grammar based on the ANTLR grammar
7d532b5c4SJan Dolinár# from https://github.com/Kotlin/kotlin-grammar-gpl2.
8d532b5c4SJan Dolinár#
9d532b5c4SJan Dolinár# Notes:
10d532b5c4SJan Dolinár#   1. This file was originally derived from files (reference grammar files) in https://github.com/Kotlin/kotlin-spec
11d532b5c4SJan Dolinár#   2. Kotlin/kotlin-spec is distributed under Apache2 license
12d532b5c4SJan Dolinár#   3. I have requested the original developers to "re-license or dual-license" (see https://github.com/Kotlin/kotlin-spec/issues/70)
13d532b5c4SJan Dolinár#   4. The request was accepted and the original developer made a new repository https://github.com/Kotlin/kotlin-grammar-gpl2
14d532b5c4SJan Dolinár#      for redistributing the reference grammar files under GPLv2 license.
15d532b5c4SJan Dolinár#   5. This file is now derived from Kotlin/kotlin-grammar-gpl2 repository.
16d532b5c4SJan Dolinár#   6. Unlike many other files in Universal Ctags, this source code is released strictly under GPLv2
17d532b5c4SJan Dolinár#      and should not be relicensed to later versions of GPL.
18d532b5c4SJan Dolinár
19d532b5c4SJan Dolinár
20d532b5c4SJan Dolinár
21d532b5c4SJan Dolinár%prefix "pkotlin"
22d532b5c4SJan Dolinár
23d532b5c4SJan Dolinár%auxil	"struct parserCtx *"
24d532b5c4SJan Dolinár
25ae30dd46SJan Dolinar%earlysource {
26ae30dd46SJan Dolinar    #include "general.h"
27ae30dd46SJan Dolinar}
28ae30dd46SJan Dolinar
29d532b5c4SJan Dolinár%header {
30d532b5c4SJan Dolinár	struct parserCtx;
31d532b5c4SJan Dolinár}
32d532b5c4SJan Dolinár
33d532b5c4SJan Dolinár%source {
34d532b5c4SJan Dolinár#include "kotlin_pre.h"
35d532b5c4SJan Dolinár}
36d532b5c4SJan Dolinár
37d532b5c4SJan Dolinárfile <- shebangLine? NL* fileAnnotation* _* packageHeader* _* importList* _* (filePart / _ / unparsable)* EOF
38d532b5c4SJan DolinárfilePart <- (topLevelObject / (statement _* semi)) {resetFailure(auxil, $0s);}
39d532b5c4SJan Dolinárunparsable <- [^\n]+ NL* {reportFailure(auxil, $0s);}
40d532b5c4SJan Dolinár
41d532b5c4SJan Dolinár### Converted from peg/kotlin/KotlinParser.g4
42d532b5c4SJan Dolinár
43d532b5c4SJan Dolinár# options
44d532b5c4SJan Dolinár# // SECTION: general
45d532b5c4SJan Dolinár#kotlinFile <- shebangLine? NL* fileAnnotation* _* packageHeader _* importList _* topLevelObject* EOF
46d532b5c4SJan Dolinár#script <- shebangLine? NL* fileAnnotation* _* packageHeader _* importList _* (statement _* semi)* EOF
47d532b5c4SJan DolinárshebangLine <- ShebangLine _* NL+
48d532b5c4SJan DolinárfileAnnotation <- (AT_NO_WS / AT_PRE_WS) FILE NL* COLON _* NL* (LSQUARE _* unescapedAnnotation+ _* RSQUARE / unescapedAnnotation) _* NL*
49*b7514e1eSMasatake YAMATOpackageHeader <- PACKAGE {PUSH_KIND(auxil, K_PACKAGE);} _ <identifier> {makeKotlinTag(auxil, $1, $1s, true);} _* semi?
50d532b5c4SJan DolinárimportList <- importHeader+
51d532b5c4SJan DolinárimportHeader <- IMPORT _ identifier (DOT MULT / importAlias)? _* semi? _*
52d532b5c4SJan DolinárimportAlias <- _ AS _ simpleIdentifier
53d532b5c4SJan DolinártopLevelObject <- declaration _* semis?
54*b7514e1eSMasatake YAMATOtypeAlias <- modifiers? _* TYPE_ALIAS {PUSH_KIND(auxil, K_TYPEALIAS);} (_ / NL)* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, false);} _* (__* typeParameters)? __* ASSIGNMENT __* type
55d532b5c4SJan Dolinárdeclaration <- classDeclaration / objectDeclaration / functionDeclaration / propertyDeclaration / typeAlias
56d532b5c4SJan Dolinár
57d532b5c4SJan Dolinár# // SECTION: classes
58*b7514e1eSMasatake YAMATOclassDeclaration <- modifiers? (CLASS {PUSH_KIND(auxil, K_CLASS);} / (FUN __*)? INTERFACE {PUSH_KIND(auxil, K_INTERFACE);}) _ NL* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, true);} (__* typeParameters)? (__* primaryConstructor)? (__* COLON __* delegationSpecifiers)? (__* typeConstraints)? (__* classBody / __* enumClassBody)? {POP_SCOPE(auxil);}
59febba3b4SJan DolinarprimaryConstructor <- (modifiers? CONSTRUCTOR __*)? classParameters
60febba3b4SJan DolinarclassBody <- LCURL __* classMemberDeclarations __* RCURL
61febba3b4SJan DolinarclassParameters <- LPAREN __* (classParameter (__* COMMA __* classParameter)* (__* COMMA)?)? __* RPAREN
62*b7514e1eSMasatake YAMATOclassParameter <- (modifiers? _* VAL {PUSH_KIND(auxil, K_CONSTANT);} / modifiers? _* VAR {PUSH_KIND(auxil, K_VARIABLE);} / modifiers? {PUSH_KIND(auxil, K_IGNORE);} _*)? __* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, true);} _* COLON __* type (__* ASSIGNMENT __* expression)? {POP_SCOPE(auxil);}
63febba3b4SJan DolinardelegationSpecifiers <- annotatedDelegationSpecifier (__* COMMA __* annotatedDelegationSpecifier)*
64d532b5c4SJan DolinárdelegationSpecifier <- constructorInvocation / explicitDelegation / userType / functionType
65d532b5c4SJan DolinárconstructorInvocation <- userType _* valueArguments
66febba3b4SJan DolinarannotatedDelegationSpecifier <- annotation* __* delegationSpecifier
67febba3b4SJan DolinarexplicitDelegation <- (userType / functionType) __* BY __* expression
68febba3b4SJan DolinartypeParameters <- LANGLE __* typeParameter (__* COMMA __* typeParameter)* (__* COMMA)? __* RANGLE
69febba3b4SJan DolinartypeParameter <- typeParameterModifiers? __* simpleIdentifier (__* COLON __* type)?
70febba3b4SJan DolinartypeConstraints <- WHERE __* typeConstraint (__* COMMA __* typeConstraint)*
71febba3b4SJan DolinartypeConstraint <- annotation* simpleIdentifier __* COLON __* type
72d532b5c4SJan Dolinár
73d532b5c4SJan Dolinár# // SECTION: classMembers
74d532b5c4SJan DolinárclassMemberDeclarations <- (classMemberDeclaration semis?)*
75d532b5c4SJan DolinárclassMemberDeclaration <- secondaryConstructor / anonymousInitializer / companionObject / declaration
76febba3b4SJan DolinaranonymousInitializer <- INIT __* block
77*b7514e1eSMasatake YAMATOcompanionObject <- modifiers? COMPANION __* OBJECT {PUSH_KIND(auxil, K_OBJECT);} <(__* simpleIdentifier)?> {makeKotlinTag(auxil, $1e-$1s != 0 ? $1 : "Companion", $1s, true);} (__* COLON __* delegationSpecifiers)? (__* classBody)? {POP_SCOPE(auxil);}
78febba3b4SJan DolinarfunctionValueParameters <- LPAREN __* (functionValueParameter (__* COMMA __* functionValueParameter)* (__* COMMA)?)? __* RPAREN
79febba3b4SJan DolinarfunctionValueParameter <- parameterModifiers? _* parameter (__* ASSIGNMENT __* expression)?
80*b7514e1eSMasatake YAMATOfunctionDeclaration <- modifiers? _* FUN {PUSH_KIND(auxil, K_METHOD);} _* (__* typeParameters)? _* (__* receiverTypeAndDot)? __* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, true);} __* functionValueParameters _* (__* COLON __* type)? _* (__* typeConstraints)? _* (__* functionBody)? {POP_SCOPE(auxil);}
81febba3b4SJan DolinarfunctionBody <- block / ASSIGNMENT __* expression
82febba3b4SJan DolinarvariableDeclaration <- annotation* __* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, false);} (__* COLON __* type)?
83febba3b4SJan DolinarmultiVariableDeclaration <- LPAREN __* variableDeclaration _* (__* COMMA __* variableDeclaration)* _* (__* COMMA)? __* RPAREN
84*b7514e1eSMasatake YAMATOpropertyDeclaration <- modifiers? _* (VAL {PUSH_KIND(auxil, K_CONSTANT);} / VAR {PUSH_KIND(auxil, K_VARIABLE);}) _ (__* typeParameters)? (__* receiverTypeAndDot)? (__* (multiVariableDeclaration / variableDeclaration)) (__* typeConstraints)? (__* (ASSIGNMENT __* expression / propertyDelegate))? (semi? _* setter (NL* semi? _* getter)? / semi? _* getter (NL* semi? _* setter)?)?
85febba3b4SJan DolinarpropertyDelegate <- BY __* expression
86d532b5c4SJan Dolinár# TODO: better handling of empty getters and setters?
87febba3b4SJan Dolinargetter <- (modifiers _*)? GET __* LPAREN __* RPAREN (__* COLON __* type)? __* functionBody / (modifiers _*)? GET !(_* [^;\r\n])
88febba3b4SJan Dolinarsetter <- (modifiers _*)? SET __* LPAREN __* parameterWithOptionalType (__* COMMA)? __* RPAREN (__* COLON __* type)? __* functionBody / (modifiers _*)? SET !(_* [^;\r\n])
89febba3b4SJan DolinarparametersWithOptionalType <- LPAREN __* (parameterWithOptionalType (__* COMMA __* parameterWithOptionalType)* (__* COMMA)?)? __* RPAREN
90febba3b4SJan DolinarparameterWithOptionalType <- parameterModifiers? simpleIdentifier __* (COLON __* type)?
91febba3b4SJan Dolinarparameter <- simpleIdentifier __* COLON __* type
92*b7514e1eSMasatake YAMATOobjectDeclaration <- modifiers? _* OBJECT {PUSH_KIND(auxil, K_OBJECT);} __* <simpleIdentifier> {makeKotlinTag(auxil, $1, $1s, true);} (__* COLON __* delegationSpecifiers)? (__* classBody)? {POP_SCOPE(auxil);}
93febba3b4SJan DolinarsecondaryConstructor <- modifiers? CONSTRUCTOR __* functionValueParameters (__* COLON __* constructorDelegationCall)? __* block?
94febba3b4SJan DolinarconstructorDelegationCall <- THIS __* valueArguments / SUPER __* valueArguments
95d532b5c4SJan Dolinár
96d532b5c4SJan Dolinár# // SECTION: enumClasses
97febba3b4SJan DolinarenumClassBody <- LCURL __* enumEntries? (__* SEMICOLON __* classMemberDeclarations)? __* RCURL
98febba3b4SJan DolinarenumEntries <- enumEntry (__* COMMA __* enumEntry)* __* COMMA?
99febba3b4SJan DolinarenumEntry <- (modifiers __*)? simpleIdentifier (__* valueArguments)? (__* classBody)?
100d532b5c4SJan Dolinár
101d532b5c4SJan Dolinár# // SECTION: types
102d532b5c4SJan Dolinártype <- typeModifiers? ( functionType / nullableType / parenthesizedType / typeReference)
103d532b5c4SJan DolinártypeReference <- userType / DYNAMIC
104febba3b4SJan DolinarnullableType <- (typeReference / parenthesizedType) __* quest+
105d532b5c4SJan Dolinárquest <- !elvis (QUEST_WS / QUEST_NO_WS)
106febba3b4SJan DolinaruserType <- simpleUserType (__* DOT __* simpleUserType)*
107febba3b4SJan DolinarsimpleUserType <- simpleIdentifier (__* typeArguments)?
108d532b5c4SJan DolinártypeProjection <- typeProjectionModifiers? type / MULT
109d532b5c4SJan DolinártypeProjectionModifiers <- typeProjectionModifier+
110febba3b4SJan DolinartypeProjectionModifier <- varianceModifier __* / annotation
111febba3b4SJan DolinarfunctionType <- (receiverType __* DOT __*)? functionTypeParameters __* ARROW __* type
112febba3b4SJan DolinarfunctionTypeParameters <- LPAREN __* (parameter / type)? _* (__* COMMA __* (parameter / type))* _* (__* COMMA)? __* RPAREN
113febba3b4SJan DolinarparenthesizedType <- LPAREN __* type __* RPAREN
114d532b5c4SJan DolinárreceiverType <- (typeModifiers _*)? (nullableType / parenthesizedType / typeReference)
115febba3b4SJan Dolinar# parenthesizedUserType <- LPAREN __* userType __* RPAREN / LPAREN __* parenthesizedUserType __* RPAREN
116febba3b4SJan DolinarreceiverTypeAndDot <- (typeModifiers _*)? (nullableType __* DOT __* / parenthesizedType __* DOT __* / (simpleUserType __* DOT __*)+)
117d532b5c4SJan Dolinár
118d532b5c4SJan Dolinár# // SECTION: statements
119d532b5c4SJan Dolinár#statements <- (statement (semis statement)*)? semis?
120d532b5c4SJan Dolinárstatements <- (statement _* (semis _* statement _*)*)? _* semis?
121d532b5c4SJan Dolinárstatement <- (label / annotation)* ( declaration / assignment / loopStatement / expression)
122febba3b4SJan Dolinarlabel <- simpleIdentifier (AT_POST_WS / AT_NO_WS) __*
123d532b5c4SJan DolinárcontrolStructureBody <- block / statement
124febba3b4SJan Dolinarblock <- LCURL __* statements __* RCURL
125d532b5c4SJan DolinárloopStatement <- forStatement / whileStatement / doWhileStatement
126febba3b4SJan DolinarforStatement <- FOR __* LPAREN _* annotation* _* (variableDeclaration / multiVariableDeclaration) _ IN _ inside_expression _* RPAREN __* (controlStructureBody)?
127febba3b4SJan DolinarwhileStatement <- WHILE __* LPAREN _* inside_expression _* RPAREN __* controlStructureBody / WHILE __* LPAREN _* expression _* RPAREN __* SEMICOLON
128febba3b4SJan DolinardoWhileStatement <- DO __* controlStructureBody? __* WHILE __* LPAREN _* expression _* RPAREN
129febba3b4SJan Dolinarassignment <- directlyAssignableExpression _* ASSIGNMENT __* expression / assignableExpression _* assignmentAndOperator __* expression
130d532b5c4SJan Dolinársemi <- (_* (SEMICOLON / NL) _*) NL*
131d532b5c4SJan Dolinársemis <- (_* (SEMICOLON / NL) _*)+
132d532b5c4SJan Dolinár
133d532b5c4SJan Dolinár# // SECTION: expressions
134d532b5c4SJan Dolinárexpression <- disjunction
135febba3b4SJan Dolinardisjunction <- conjunction (__* DISJ __* conjunction)*
136febba3b4SJan Dolinarconjunction <- equality (__* CONJ __* equality)*
137febba3b4SJan Dolinarequality <- comparison (_* equalityOperator __* comparison _*)*
138febba3b4SJan Dolinarcomparison <- genericCallLikeComparison (_* comparisonOperator __* genericCallLikeComparison _*)*
139d532b5c4SJan DolinárgenericCallLikeComparison <- infixOperation (_* callSuffix)*
140febba3b4SJan DolinarinfixOperation <- elvisExpression (_* inOperator __* elvisExpression / _* isOperator __* type)*
141febba3b4SJan DolinarelvisExpression <- infixFunctionCall (__* elvis __* infixFunctionCall)*
142d532b5c4SJan Dolinárelvis <- QUEST_NO_WS COLON
143febba3b4SJan DolinarinfixFunctionCall <- rangeExpression (_* simpleIdentifier __* rangeExpression)*
144febba3b4SJan DolinarrangeExpression <- additiveExpression (_* RANGE __* additiveExpression)*
145febba3b4SJan DolinaradditiveExpression <- multiplicativeExpression (_* additiveOperator __* multiplicativeExpression)*
146febba3b4SJan DolinarmultiplicativeExpression <- asExpression (_* multiplicativeOperator __* asExpression)*
147febba3b4SJan DolinarasExpression <- prefixUnaryExpression (__* asOperator __* type)*
148d532b5c4SJan DolinárprefixUnaryExpression <- (unaryPrefix _*)* postfixUnaryExpression
149febba3b4SJan DolinarunaryPrefix <- annotation / label / prefixUnaryOperator __*
150d532b5c4SJan DolinárpostfixUnaryExpression <- primaryExpression (_* postfixUnarySuffix)+ / primaryExpression
151d532b5c4SJan DolinárpostfixUnarySuffix <- postfixUnaryOperator / typeArguments / callSuffix / indexingSuffix / navigationSuffix
152d532b5c4SJan DolinárdirectlyAssignableExpression <- postfixUnaryExpression _* assignableSuffix / postfixUnaryExpression / simpleIdentifier / parenthesizedDirectlyAssignableExpression
153febba3b4SJan DolinarparenthesizedDirectlyAssignableExpression <- LPAREN __* inside_directlyAssignableExpression __* RPAREN
154d532b5c4SJan DolinárassignableExpression <- prefixUnaryExpression / parenthesizedAssignableExpression
155febba3b4SJan DolinarparenthesizedAssignableExpression <- LPAREN __* inside_assignableExpression __* RPAREN
156d532b5c4SJan DolinárassignableSuffix <- navigationSuffix / typeArguments / indexingSuffix
157febba3b4SJan DolinarindexingSuffix <- LSQUARE __* inside_expression (__* COMMA __* inside_expression)* (__* COMMA)? __* RSQUARE
158febba3b4SJan DolinarnavigationSuffix <- __* memberAccessOperator __* (simpleIdentifier / parenthesizedExpression / CLASS)
159d532b5c4SJan DolinárcallSuffix <- typeArguments? _* valueArguments? _* annotatedLambda / typeArguments? _* valueArguments
160febba3b4SJan DolinarannotatedLambda <- annotation* _* label? __* lambdaLiteral
161febba3b4SJan DolinartypeArguments <- LANGLE __* typeProjection (__* COMMA __* typeProjection)* (__* COMMA)? __* RANGLE
162febba3b4SJan DolinarvalueArguments <- LPAREN __* RPAREN / LPAREN __* inside_valueArgument (__* COMMA __* inside_valueArgument)* (__* COMMA)? __* RPAREN
163febba3b4SJan Dolinar#valueArgument <- annotation? __* (simpleIdentifier __* ASSIGNMENT __*)? MULT? __* expression
164d532b5c4SJan DolinárprimaryExpression <- thisExpression / superExpression / ifExpression / whenExpression / tryExpression / jumpExpression / parenthesizedExpression/ callableReference / stringLiteral / functionLiteral / objectLiteral / collectionLiteral  / simpleIdentifier / literalConstant
165febba3b4SJan DolinarparenthesizedExpression <- LPAREN __* inside_expression __* RPAREN
166febba3b4SJan DolinarcollectionLiteral <- LSQUARE __* inside_expression (__* COMMA __* inside_expression)* (__* COMMA)? __* RSQUARE / LSQUARE __* RSQUARE
167d532b5c4SJan DolinárliteralConstant <- BooleanLiteral / CharacterLiteral / NullLiteral / RealLiteral / UnsignedLiteral / LongLiteral / HexLiteral / BinLiteral / IntegerLiteral
168d532b5c4SJan DolinárstringLiteral <- multiLineStringLiteral / lineStringLiteral
169d532b5c4SJan DolinárlineStringLiteral <- QUOTE_OPEN (lineStringExpression / lineStringContent)* QUOTE_CLOSE
170d532b5c4SJan Dolinár#lineStringLiteral <- QUOTE_OPEN (lineStringExpression / EscapedIdentifier / UniCharacterLiteral / stringChar)* QUOTE_CLOSE
171d532b5c4SJan DolinármultiLineStringLiteral <- TRIPLE_QUOTE_OPEN (multiLineStringExpression / multiLineStringContent / MultiLineStringQuote)* TRIPLE_QUOTE_CLOSE
172d532b5c4SJan Dolinár#multiLineStringLiteral <- TRIPLE_QUOTE_OPEN (multiLineStringExpression / MultiLineStringQuote / EscapedIdentifier / UniChracterLiteral / stringChar)* TRIPLE_QUOTE_CLOSE
173d532b5c4SJan DolinárlineStringContent <- LineStrText / LineStrEscapedChar / LineStrRef
174febba3b4SJan DolinarlineStringExpression <- LineStrExprStart __* expression __* RCURL
175d532b5c4SJan DolinármultiLineStringContent <- MultiLineStrRef / MultiLineStrText / MultiLineStringQuote
176febba3b4SJan DolinarmultiLineStringExpression <- MultiLineStrExprStart __* expression __* RCURL
177d532b5c4SJan Dolinár
178d532b5c4SJan Dolinárinside_expression <- inside_disjunction
179febba3b4SJan Dolinarinside_disjunction <- inside_conjunction (__* DISJ __* inside_conjunction)*
180febba3b4SJan Dolinarinside_conjunction <- inside_equality (__* CONJ __* inside_equality)*
181febba3b4SJan Dolinarinside_equality <- inside_comparison ((_ / NL)* equalityOperator __* inside_comparison (_ / NL)*)*
182febba3b4SJan Dolinarinside_comparison <- inside_genericCallLikeComparison ((_ / NL)* comparisonOperator __* inside_genericCallLikeComparison (_ / NL)*)*
183d532b5c4SJan Dolinárinside_genericCallLikeComparison <- inside_infixOperation ((_ / NL)* callSuffix)*
184febba3b4SJan Dolinarinside_infixOperation <- inside_elvisExpression ((_ / NL)* inOperator __* inside_elvisExpression / (_ / NL)* isOperator __* type)*
185febba3b4SJan Dolinarinside_elvisExpression <- inside_infixFunctionCall (__* elvis __* inside_infixFunctionCall)*
186febba3b4SJan Dolinarinside_infixFunctionCall <- inside_rangeExpression ((_ / NL)* simpleIdentifier __* inside_rangeExpression)*
187febba3b4SJan Dolinarinside_rangeExpression <- inside_additiveExpression ((_ / NL)* RANGE __* inside_additiveExpression)*
188febba3b4SJan Dolinarinside_additiveExpression <- inside_multiplicativeExpression ((_ / NL)* additiveOperator __* inside_multiplicativeExpression)*
189febba3b4SJan Dolinarinside_multiplicativeExpression <- inside_asExpression ((_ / NL)* multiplicativeOperator __* inside_asExpression)*
190febba3b4SJan Dolinarinside_asExpression <- inside_prefixUnaryExpression (__* asOperator __* type)*
191d532b5c4SJan Dolinárinside_prefixUnaryExpression <- (inside_unaryPrefix (_ / NL)*)* inside_postfixUnaryExpression
192febba3b4SJan Dolinarinside_unaryPrefix <- annotation / label / prefixUnaryOperator __*
193d532b5c4SJan Dolinárinside_postfixUnaryExpression <- primaryExpression ((_ / NL)* inside_postfixUnarySuffix)+ / primaryExpression
194d532b5c4SJan Dolinárinside_postfixUnarySuffix <- postfixUnaryOperator / typeArguments / callSuffix / indexingSuffix / navigationSuffix
195d532b5c4SJan Dolinárinside_directlyAssignableExpression <- inside_postfixUnaryExpression (_ / NL)* assignableSuffix / inside_postfixUnaryExpression / simpleIdentifier / parenthesizedDirectlyAssignableExpression
196d532b5c4SJan Dolinárinside_assignableExpression <- inside_prefixUnaryExpression / parenthesizedAssignableExpression
197febba3b4SJan Dolinarinside_valueArgument <- annotation? __* (simpleIdentifier __* ASSIGNMENT __*)? MULT? __* inside_expression
198d532b5c4SJan Dolinár
199d532b5c4SJan Dolinár
200d532b5c4SJan Dolinár#characterLiteral <- "'" (UniCharacterLiteral / EscapedIdentifier / [^\n\r'\\]) "'"
201d532b5c4SJan Dolinár#stringChar <- [^"]
202d532b5c4SJan Dolinár
203*b7514e1eSMasatake YAMATOlambdaLiteral <- LCURL {PUSH_KIND(auxil, K_METHOD); makeKotlinTag(auxil, "<lambda>", $0s, true);} __* statements __* RCURL {POP_SCOPE(auxil);} / LCURL {PUSH_KIND(auxil, K_METHOD); makeKotlinTag(auxil, "<lambda>", 8, true);} __* lambdaParameters? __* ARROW __* statements __* RCURL {POP_SCOPE(auxil);}
204febba3b4SJan DolinarlambdaParameters <- lambdaParameter (__* COMMA __* lambdaParameter)* (__* COMMA)?
205febba3b4SJan DolinarlambdaParameter <- variableDeclaration / multiVariableDeclaration (__* COLON __* type)?
206*b7514e1eSMasatake YAMATOanonymousFunction <- FUN {PUSH_KIND(auxil, K_METHOD); makeKotlinTag(auxil, "<anonymous>", $0s, true);} (__* type __* DOT)? __* parametersWithOptionalType (__* COLON __* type)? (__* typeConstraints)? (__* functionBody)? {POP_SCOPE(auxil);}
207d532b5c4SJan DolinárfunctionLiteral <- lambdaLiteral / anonymousFunction
208febba3b4SJan DolinarobjectLiteral <- OBJECT __* COLON __* delegationSpecifiers __* classBody / OBJECT __* classBody
209d532b5c4SJan DolinárthisExpression <- THIS_AT / THIS !(Letter / UnicodeDigit)
210febba3b4SJan DolinarsuperExpression <- SUPER_AT / SUPER (LANGLE __* type __* RANGLE)? (AT_NO_WS simpleIdentifier)?
211febba3b4SJan DolinarifExpression <- IF __* LPAREN __* expression __* RPAREN __* controlStructureBody? __* SEMICOLON? __* ELSE __* (controlStructureBody / SEMICOLON) / IF __* LPAREN __* expression __* RPAREN __* (controlStructureBody / SEMICOLON)
212febba3b4SJan DolinarwhenSubject <- LPAREN (annotation* __* VAL __* variableDeclaration __* ASSIGNMENT __*)? expression RPAREN
213febba3b4SJan DolinarwhenExpression <- WHEN __* whenSubject? __* LCURL __* (whenEntry __*)* __* RCURL
214febba3b4SJan DolinarwhenEntry <- whenCondition (__* COMMA __* whenCondition)* (__* COMMA)? __* ARROW __* controlStructureBody semi? / ELSE __* ARROW __* controlStructureBody semi?
215d532b5c4SJan DolinárwhenCondition <- expression / rangeTest / typeTest
216febba3b4SJan DolinarrangeTest <- inOperator __* expression
217febba3b4SJan DolinartypeTest <- isOperator __* type
218febba3b4SJan DolinartryExpression <- TRY __* block ((__* catchBlock)+ (__* finallyBlock)? / __* finallyBlock)
219febba3b4SJan DolinarcatchBlock <- CATCH __* LPAREN _* (annotation _*)* simpleIdentifier _* COLON _* type (__* COMMA)? _* RPAREN __* block
220febba3b4SJan DolinarfinallyBlock <- FINALLY __* block
221febba3b4SJan DolinarjumpExpression <- THROW __* expression / (RETURN_AT / RETURN) _* expression? / CONTINUE_AT / CONTINUE / BREAK_AT / BREAK
222febba3b4SJan DolinarcallableReference <- (receiverType? __* COLONCOLON __* (simpleIdentifier / CLASS))
223d532b5c4SJan DolinárassignmentAndOperator <- ADD_ASSIGNMENT / SUB_ASSIGNMENT / MULT_ASSIGNMENT / DIV_ASSIGNMENT / MOD_ASSIGNMENT
224d532b5c4SJan DolinárequalityOperator <- EQEQEQ / EQEQ / EXCL_EQEQ / EXCL_EQ
225d532b5c4SJan DolinárcomparisonOperator <- LE / GE / LANGLE / RANGLE
226d532b5c4SJan DolinárinOperator <- IN / NOT_IN
227d532b5c4SJan DolinárisOperator <- IS / NOT_IS
228d532b5c4SJan DolináradditiveOperator <- ADD / SUB
229d532b5c4SJan DolinármultiplicativeOperator <- MULT / DIV / MOD
230d532b5c4SJan DolinárasOperator <- AS_SAFE / AS
231d532b5c4SJan DolinárprefixUnaryOperator <- INCR / DECR / SUB / ADD / excl
232d532b5c4SJan DolinárpostfixUnaryOperator <- INCR / DECR / EXCL_NO_WS excl
233d532b5c4SJan Dolinárexcl <- EXCL_WS / EXCL_NO_WS
234d532b5c4SJan DolinármemberAccessOperator <- DOT / safeNav / COLONCOLON
235d532b5c4SJan DolinársafeNav <- QUEST_NO_WS DOT
236d532b5c4SJan Dolinár
237d532b5c4SJan Dolinár# // SECTION: modifiers
238d532b5c4SJan Dolinármodifiers <- (annotation / modifier)+
239d532b5c4SJan DolinárparameterModifiers <- (annotation / parameterModifier)+
240febba3b4SJan Dolinarmodifier <- (classModifier / memberModifier / visibilityModifier / functionModifier / propertyModifier / inheritanceModifier / parameterModifier / platformModifier) __*
241d532b5c4SJan DolinártypeModifiers <- typeModifier+
242febba3b4SJan DolinartypeModifier <- annotation / SUSPEND __*
243d532b5c4SJan DolinárclassModifier <- ENUM / SEALED / ANNOTATION / DATA / INNER
244d532b5c4SJan DolinármemberModifier <- OVERRIDE / LATEINIT
245d532b5c4SJan DolinárvisibilityModifier <- PUBLIC / PRIVATE / INTERNAL / PROTECTED
246d532b5c4SJan DolinárvarianceModifier <- IN / OUT
247d532b5c4SJan DolinártypeParameterModifiers <- typeParameterModifier+
248febba3b4SJan DolinartypeParameterModifier <- reificationModifier __* / varianceModifier __* / annotation
249d532b5c4SJan DolinárfunctionModifier <- TAILREC / OPERATOR / INFIX / INLINE / EXTERNAL / SUSPEND
250d532b5c4SJan DolinárpropertyModifier <- CONST
251d532b5c4SJan DolinárinheritanceModifier <- ABSTRACT / FINAL / OPEN
252d532b5c4SJan DolinárparameterModifier <- VARARG / NOINLINE / CROSSINLINE
253d532b5c4SJan DolinárreificationModifier <- REIFIED
254d532b5c4SJan DolinárplatformModifier <- EXPECT / ACTUAL
255d532b5c4SJan Dolinár
256d532b5c4SJan Dolinár# // SECTION: annotations
257febba3b4SJan Dolinarannotation <- (singleAnnotation / multiAnnotation) __*
258febba3b4SJan DolinarsingleAnnotation <- annotationUseSiteTarget __* unescapedAnnotation / (AT_NO_WS / AT_PRE_WS) unescapedAnnotation
259febba3b4SJan DolinarmultiAnnotation <- annotationUseSiteTarget __* LSQUARE unescapedAnnotation+ RSQUARE / (AT_NO_WS / AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE
260febba3b4SJan DolinarannotationUseSiteTarget <- (AT_NO_WS / AT_PRE_WS) (FIELD / PROPERTY / GET / SET / RECEIVER / PARAM / SETPARAM / DELEGATE) __* COLON
261d532b5c4SJan DolinárunescapedAnnotation <- constructorInvocation / userType
262d532b5c4SJan Dolinár
263d532b5c4SJan Dolinár# // SECTION: identifiers
264d532b5c4SJan DolinársimpleIdentifier <- !(hardKeyword !(Letter / '_' / UnicodeDigit)) 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
265febba3b4SJan Dolinaridentifier <- simpleIdentifier (__* DOT simpleIdentifier)*
266d532b5c4SJan Dolinár
267d532b5c4SJan DolinárhardKeyword <- AS / BREAK / CLASS / CONTINUE / DO / ELSE / FOR / FUN / IF / IN / INTERFACE / IS / NullLiteral / OBJECT / PACKAGE / RETURN / SUPER / THIS / THROW / TRY / TYPE_ALIAS / TYPEOF / VAL / VAR / WHEN / WHILE / BooleanLiteral
268d532b5c4SJan Dolinár
269d532b5c4SJan Dolinár
270d532b5c4SJan Dolinár### Converted from peg/kotlin/KotlinLexer.g4
271d532b5c4SJan Dolinár
272d532b5c4SJan Dolinár
273d532b5c4SJan Dolinár# // SECTION: lexicalGeneral
274d532b5c4SJan DolinárShebangLine <- '#!' [^\r\n]*
275d532b5c4SJan DolinárDelimitedComment <- '/*' (DelimitedComment / !'*/' .)* '*/'
276d532b5c4SJan DolinárLineComment <- '//' [^\r\n]*
277d532b5c4SJan Dolinár#WS <- [\u0020\u0009\u000C]
278d532b5c4SJan Dolinár#NL <- '\n' / '\r' '\n'?
279d532b5c4SJan DolinárHidden <- DelimitedComment / LineComment / WS
280d532b5c4SJan Dolinár
281d532b5c4SJan Dolinár# // SECTION: separatorsAndOperations
282d532b5c4SJan Dolinár#RESERVED <- '...'
283d532b5c4SJan DolinárDOT <- '.'
284d532b5c4SJan DolinárCOMMA <- ','
285d532b5c4SJan DolinárLPAREN <- '('
286d532b5c4SJan DolinárRPAREN <- ')'
287d532b5c4SJan DolinárLSQUARE <- '['
288d532b5c4SJan DolinárRSQUARE <- ']'
289d532b5c4SJan DolinárLCURL <- '{'
290d532b5c4SJan Dolinár# /*
291d532b5c4SJan Dolinár# * When using another programming language (not Java) to generate a parser,
292d532b5c4SJan Dolinár# * please replace this code with the corresponding code of a programming language you are using.
293d532b5c4SJan Dolinár# */
294d532b5c4SJan DolinárRCURL <- '}'
295d532b5c4SJan DolinárMULT <- '*'
296d532b5c4SJan DolinárMOD <- '%'
297d532b5c4SJan DolinárDIV <- '/'
298d532b5c4SJan DolinárADD <- '+'
299d532b5c4SJan DolinárSUB <- '-'
300d532b5c4SJan DolinárINCR <- '++'
301d532b5c4SJan DolinárDECR <- '--'
302d532b5c4SJan DolinárCONJ <- '&&'
303d532b5c4SJan DolinárDISJ <- '||'
304d532b5c4SJan DolinárEXCL_WS <- '!' Hidden
305d532b5c4SJan DolinárEXCL_NO_WS <- '!'
306d532b5c4SJan DolinárCOLON <- ':'
307d532b5c4SJan DolinárSEMICOLON <- ';'
308d532b5c4SJan DolinárASSIGNMENT <- '=' !'='
309d532b5c4SJan DolinárADD_ASSIGNMENT <- '+='
310d532b5c4SJan DolinárSUB_ASSIGNMENT <- '-='
311d532b5c4SJan DolinárMULT_ASSIGNMENT <- '*='
312d532b5c4SJan DolinárDIV_ASSIGNMENT <- '/='
313d532b5c4SJan DolinárMOD_ASSIGNMENT <- '%='
314d532b5c4SJan DolinárARROW <- '->'
315d532b5c4SJan Dolinár#DOUBLE_ARROW <- '=>'
316d532b5c4SJan DolinárRANGE <- '..'
317d532b5c4SJan DolinárCOLONCOLON <- '::'
318d532b5c4SJan Dolinár#DOUBLE_SEMICOLON <- ';;'
319d532b5c4SJan Dolinár#HASH <- '#'
320d532b5c4SJan DolinárAT_NO_WS <- '@'
321d532b5c4SJan DolinárAT_POST_WS <- '@' (Hidden / NL)
322d532b5c4SJan DolinárAT_PRE_WS <- (Hidden / NL) '@'
323d532b5c4SJan Dolinár#AT_BOTH_WS <- (Hidden / NL) '@' (Hidden / NL)
324d532b5c4SJan DolinárQUEST_WS <- '?' Hidden
325d532b5c4SJan DolinárQUEST_NO_WS <- '?'
326d532b5c4SJan DolinárLANGLE <- '<'
327d532b5c4SJan DolinárRANGLE <- '>'
328d532b5c4SJan DolinárLE <- '<='
329d532b5c4SJan DolinárGE <- '>='
330d532b5c4SJan DolinárEXCL_EQ <- '!='
331d532b5c4SJan DolinárEXCL_EQEQ <- '!=='
332d532b5c4SJan DolinárAS_SAFE <- 'as?'
333d532b5c4SJan DolinárEQEQ <- '=='
334d532b5c4SJan DolinárEQEQEQ <- '==='
335d532b5c4SJan Dolinár#SINGLE_QUOTE <- '\''
336d532b5c4SJan Dolinár
337d532b5c4SJan Dolinár# // SECTION: keywords
338d532b5c4SJan DolinárRETURN_AT <- 'return@' Identifier
339d532b5c4SJan DolinárCONTINUE_AT <- 'continue@' Identifier
340d532b5c4SJan DolinárBREAK_AT <- 'break@' Identifier
341d532b5c4SJan DolinárTHIS_AT <- 'this@' Identifier
342d532b5c4SJan DolinárSUPER_AT <- 'super@' Identifier
343d532b5c4SJan DolinárFILE <- 'file' !(Letter / UnicodeDigit)
344d532b5c4SJan DolinárFIELD <- 'field' !(Letter / UnicodeDigit)
345d532b5c4SJan DolinárPROPERTY <- 'property' !(Letter / UnicodeDigit)
346d532b5c4SJan DolinárGET <- 'get' !(Letter / UnicodeDigit)
347d532b5c4SJan DolinárSET <- 'set' !(Letter / UnicodeDigit)
348d532b5c4SJan DolinárRECEIVER <- 'receiver' !(Letter / UnicodeDigit)
349d532b5c4SJan DolinárPARAM <- 'param' !(Letter / UnicodeDigit)
350d532b5c4SJan DolinárSETPARAM <- 'setparam' !(Letter / UnicodeDigit)
351d532b5c4SJan DolinárDELEGATE <- 'delegate' !(Letter / UnicodeDigit)
352d532b5c4SJan DolinárPACKAGE <- 'package' !(Letter / UnicodeDigit)
353d532b5c4SJan DolinárIMPORT <- 'import' !(Letter / UnicodeDigit)
354d532b5c4SJan DolinárCLASS <- 'class' !(Letter / UnicodeDigit)
355d532b5c4SJan DolinárINTERFACE <- 'interface' !(Letter / UnicodeDigit)
356d532b5c4SJan DolinárFUN <- 'fun' !(Letter / UnicodeDigit)
357d532b5c4SJan DolinárOBJECT <- 'object' !(Letter / UnicodeDigit)
358d532b5c4SJan DolinárVAL <- 'val' !(Letter / UnicodeDigit)
359d532b5c4SJan DolinárVAR <- 'var' !(Letter / UnicodeDigit)
360d532b5c4SJan DolinárTYPE_ALIAS <- 'typealias' !(Letter / UnicodeDigit)
361d532b5c4SJan DolinárCONSTRUCTOR <- 'constructor' !(Letter / UnicodeDigit)
362d532b5c4SJan DolinárBY <- 'by' !(Letter / UnicodeDigit)
363d532b5c4SJan DolinárCOMPANION <- 'companion' !(Letter / UnicodeDigit)
364d532b5c4SJan DolinárINIT <- 'init' !(Letter / UnicodeDigit)
365d532b5c4SJan DolinárTHIS <- 'this' !(Letter / UnicodeDigit)
366d532b5c4SJan DolinárSUPER <- 'super' !(Letter / UnicodeDigit)
367d532b5c4SJan DolinárTYPEOF <- 'typeof' !(Letter / UnicodeDigit)
368d532b5c4SJan DolinárWHERE <- 'where' !(Letter / UnicodeDigit)
369d532b5c4SJan DolinárIF <- 'if' !(Letter / UnicodeDigit)
370d532b5c4SJan DolinárELSE <- 'else' !(Letter / UnicodeDigit)
371d532b5c4SJan DolinárWHEN <- 'when' !(Letter / UnicodeDigit)
372d532b5c4SJan DolinárTRY <- 'try' !(Letter / UnicodeDigit)
373d532b5c4SJan DolinárCATCH <- 'catch' !(Letter / UnicodeDigit)
374d532b5c4SJan DolinárFINALLY <- 'finally' !(Letter / UnicodeDigit)
375d532b5c4SJan DolinárFOR <- 'for' !(Letter / UnicodeDigit)
376d532b5c4SJan DolinárDO <- 'do' !(Letter / UnicodeDigit)
377d532b5c4SJan DolinárWHILE <- 'while' !(Letter / UnicodeDigit)
378d532b5c4SJan DolinárTHROW <- 'throw' !(Letter / UnicodeDigit)
379d532b5c4SJan DolinárRETURN <- 'return' !(Letter / UnicodeDigit)
380d532b5c4SJan DolinárCONTINUE <- 'continue' !(Letter / UnicodeDigit)
381d532b5c4SJan DolinárBREAK <- 'break' !(Letter / UnicodeDigit)
382d532b5c4SJan DolinárAS <- 'as' !(Letter / UnicodeDigit)
383d532b5c4SJan DolinárIS <- 'is' !(Letter / UnicodeDigit)
384d532b5c4SJan DolinárIN <- 'in' !(Letter / UnicodeDigit)
385d532b5c4SJan DolinárNOT_IS <- '!is' !(Letter / UnicodeDigit)
386d532b5c4SJan DolinárNOT_IN <- '!in' !(Letter / UnicodeDigit)
387d532b5c4SJan DolinárOUT <- 'out' !(Letter / UnicodeDigit)
388d532b5c4SJan DolinárDYNAMIC <- 'dynamic' !(Letter / UnicodeDigit)
389d532b5c4SJan Dolinár
390d532b5c4SJan Dolinár# // SECTION: lexicalModifiers
391d532b5c4SJan DolinárPUBLIC <- 'public' !(Letter / UnicodeDigit)
392d532b5c4SJan DolinárPRIVATE <- 'private' !(Letter / UnicodeDigit)
393d532b5c4SJan DolinárPROTECTED <- 'protected' !(Letter / UnicodeDigit)
394d532b5c4SJan DolinárINTERNAL <- 'internal' !(Letter / UnicodeDigit)
395d532b5c4SJan DolinárENUM <- 'enum' !(Letter / UnicodeDigit)
396d532b5c4SJan DolinárSEALED <- 'sealed' !(Letter / UnicodeDigit)
397d532b5c4SJan DolinárANNOTATION <- 'annotation' !(Letter / UnicodeDigit)
398d532b5c4SJan DolinárDATA <- 'data' !(Letter / UnicodeDigit)
399d532b5c4SJan DolinárINNER <- 'inner' !(Letter / UnicodeDigit)
400d532b5c4SJan DolinárTAILREC <- 'tailrec' !(Letter / UnicodeDigit)
401d532b5c4SJan DolinárOPERATOR <- 'operator' !(Letter / UnicodeDigit)
402d532b5c4SJan DolinárINLINE <- 'inline' !(Letter / UnicodeDigit)
403d532b5c4SJan DolinárINFIX <- 'infix' !(Letter / UnicodeDigit)
404d532b5c4SJan DolinárEXTERNAL <- 'external' !(Letter / UnicodeDigit)
405d532b5c4SJan DolinárSUSPEND <- 'suspend' !(Letter / UnicodeDigit)
406d532b5c4SJan DolinárOVERRIDE <- 'override' !(Letter / UnicodeDigit)
407d532b5c4SJan DolinárABSTRACT <- 'abstract' !(Letter / UnicodeDigit)
408d532b5c4SJan DolinárFINAL <- 'final' !(Letter / UnicodeDigit)
409d532b5c4SJan DolinárOPEN <- 'open' !(Letter / UnicodeDigit)
410d532b5c4SJan DolinárCONST <- 'const' !(Letter / UnicodeDigit)
411d532b5c4SJan DolinárLATEINIT <- 'lateinit' !(Letter / UnicodeDigit)
412d532b5c4SJan DolinárVARARG <- 'vararg' !(Letter / UnicodeDigit)
413d532b5c4SJan DolinárNOINLINE <- 'noinline' !(Letter / UnicodeDigit)
414d532b5c4SJan DolinárCROSSINLINE <- 'crossinline' !(Letter / UnicodeDigit)
415d532b5c4SJan DolinárREIFIED <- 'reified' !(Letter / UnicodeDigit)
416d532b5c4SJan DolinárEXPECT <- 'expect' !(Letter / UnicodeDigit)
417d532b5c4SJan DolinárACTUAL <- 'actual' !(Letter / UnicodeDigit)
418d532b5c4SJan Dolinár
419d532b5c4SJan Dolinár# // SECTION: literals
420d532b5c4SJan DolinárDecDigit <- [0-9]
421d532b5c4SJan DolinárDecDigitNoZero <- [1-9]
422d532b5c4SJan DolinárDecDigitOrSeparator <- DecDigit / '_'
423d532b5c4SJan DolinárDecDigits <- DecDigit DecDigitOrSeparator* / DecDigit
424febba3b4SJan DolinarDoubleExponent <- [eE] [-+]? DecDigits
425d532b5c4SJan DolinárRealLiteral <- FloatLiteral / DoubleLiteral
426d532b5c4SJan DolinárFloatLiteral <- DoubleLiteral [fF] / DecDigits [fF]
427d532b5c4SJan DolinárDoubleLiteral <- DecDigits? '.' DecDigits DoubleExponent? / DecDigits DoubleExponent
428d532b5c4SJan DolinárIntegerLiteral <- DecDigitNoZero DecDigitOrSeparator* / DecDigit
429d532b5c4SJan Dolinár#IntegerLiteral <- DecDigitNoZero DecDigitOrSeparator* DecDigit / DecDigit
430d532b5c4SJan DolinárHexDigit <- [0-9a-fA-F]
431d532b5c4SJan DolinárHexDigitOrSeparator <- HexDigit / '_'
432d532b5c4SJan DolinárHexLiteral <- '0' [xX] HexDigit HexDigitOrSeparator* / '0' [xX] HexDigit
433d532b5c4SJan DolinárBinDigit <- [01]
434d532b5c4SJan DolinárBinDigitOrSeparator <- BinDigit / '_'
435d532b5c4SJan DolinárBinLiteral <- '0' [bB] BinDigit BinDigitOrSeparator* / '0' [bB] BinDigit
436d532b5c4SJan DolinárUnsignedLiteral <- (HexLiteral / BinLiteral / IntegerLiteral) [uU] [lL]?
437d532b5c4SJan DolinárLongLiteral <- (HexLiteral / BinLiteral / IntegerLiteral) [lL]
438d532b5c4SJan DolinárBooleanLiteral <- 'true'/ 'false'
439d532b5c4SJan DolinárNullLiteral <- 'null'
440d532b5c4SJan DolinárCharacterLiteral <- '\'' (EscapeSeq / [^\n\r'\\]) '\''
441d532b5c4SJan Dolinár
442d532b5c4SJan Dolinár# // SECTION: lexicalIdentifiers
443d532b5c4SJan Dolinár#UnicodeDigit <- UNICODE_CLASS_ND
444d532b5c4SJan DolinárIdentifier <- '`' [^`\r\n]+ '`' / (Letter / '_') (Letter / '_' / UnicodeDigit)*
445d532b5c4SJan DolinárIdentifierOrSoftKey <- 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
446d532b5c4SJan DolinárFieldIdentifier <- '$' IdentifierOrSoftKey
447d532b5c4SJan DolinárUniCharacterLiteral <- '\\' 'u' HexDigit HexDigit HexDigit HexDigit
448d532b5c4SJan DolinárEscapedIdentifier <- '\\' ('t' / 'b' / 'r' / 'n' / '\'' / '"' / '\\' / '$')
449d532b5c4SJan DolinárEscapeSeq <- UniCharacterLiteral / EscapedIdentifier
450d532b5c4SJan Dolinár
451d532b5c4SJan Dolinár# // SECTION: characters
452febba3b4SJan DolinarLetter <- [\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376-\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E-\u066F\u0671-\u06D3\u06D5\u06E5-\u06E6\u06EE-\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4-\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0-\u0AE1\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58-\u0C59\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0-\u0CE1\u0CF1-\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E46\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065-\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE-\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5-\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400\u4DB5\u4E00\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A-\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5-\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40-\uFB41\uFB43-\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]
453febba3b4SJan DolinarUnicodeDigit <- [\u0030-\u0039\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19]
454d532b5c4SJan Dolinár
455d532b5c4SJan Dolinár# // SECTION: strings
456d532b5c4SJan DolinárQUOTE_OPEN <- '"' !'""'
457d532b5c4SJan DolinárTRIPLE_QUOTE_OPEN <- '"""'
458d532b5c4SJan DolinárQUOTE_CLOSE <- '"'
459d532b5c4SJan DolinárLineStrRef <- FieldIdentifier
460d532b5c4SJan Dolinár#LineStrText <- [^\\"$]+ / '$'
461d532b5c4SJan DolinárLineStrText <- [^\\"$]+ / '$'
462d532b5c4SJan DolinárLineStrEscapedChar <- EscapedIdentifier / UniCharacterLiteral
463d532b5c4SJan DolinárLineStrExprStart <- '${'
464d532b5c4SJan DolinárTRIPLE_QUOTE_CLOSE <- '"""""'/ '""""' / '"""'
465d532b5c4SJan DolinárMultiLineStringQuote <- '""' !'"' / '"' !'""'
466d532b5c4SJan DolinárMultiLineStrRef <- FieldIdentifier
467d532b5c4SJan Dolinár#MultiLineStrText <- !('"' / '$')+ / '$'
468d532b5c4SJan DolinárMultiLineStrText <- [^"$]+ / '$'
469d532b5c4SJan DolinárMultiLineStrExprStart <- '${'
470d532b5c4SJan Dolinár
471d532b5c4SJan Dolinár_ <- (WS / DelimitedComment / LineComment)+
472febba3b4SJan Dolinar__ <- ([ \t\f\r\n] / DelimitedComment / LineComment)+
473febba3b4SJan DolinarWS <- [ \t\f]
474d532b5c4SJan DolinárNL <- _* ('\n' / '\r' '\n'?) _*
475d532b5c4SJan DolinárEOF <- !.
476d532b5c4SJan Dolinár
477d532b5c4SJan Dolinár%%
478d532b5c4SJan Dolinár#include "kotlin_post.h"
479