Skip to content

Commit c415d2e

Browse files
KvanTTTdrieks
authored andcommitted
Fix "Inconsistent formatting for rule alternatives" (fix #36), "Get rid of duplication in rule alternatives" (fix #35), clear up
Max line length = 120
1 parent 7a60784 commit c415d2e

File tree

1 file changed

+73
-81
lines changed

1 file changed

+73
-81
lines changed

grammar-kotlin-parser-common/src/commonAntlr/antlr/KotlinParser.g4

Lines changed: 73 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ declaration
6060

6161
classDeclaration
6262
: modifiers? (CLASS | (FUN NL*)? INTERFACE) NL* simpleIdentifier
63-
(NL* typeParameters)? (NL* primaryConstructor)?
64-
(NL* COLON NL* delegationSpecifiers)?
65-
(NL* typeConstraints)?
66-
(NL* classBody | NL* enumClassBody)?
63+
(NL* typeParameters)? (NL* primaryConstructor)?
64+
(NL* COLON NL* delegationSpecifiers)?
65+
(NL* typeConstraints)?
66+
(NL* classBody | NL* enumClassBody)?
6767
;
6868

6969
primaryConstructor
@@ -140,9 +140,9 @@ anonymousInitializer
140140

141141
companionObject
142142
: modifiers? COMPANION NL* OBJECT
143-
(NL* simpleIdentifier)?
144-
(NL* COLON NL* delegationSpecifiers)?
145-
(NL* classBody)?
143+
(NL* simpleIdentifier)?
144+
(NL* COLON NL* delegationSpecifiers)?
145+
(NL* classBody)?
146146
;
147147

148148
functionValueParameters
@@ -155,11 +155,11 @@ functionValueParameter
155155

156156
functionDeclaration
157157
: modifiers?
158-
FUN (NL* typeParameters)? (NL* receiverType NL* DOT)? NL* simpleIdentifier
159-
NL* functionValueParameters
160-
(NL* COLON NL* type)?
161-
(NL* typeConstraints)?
162-
(NL* functionBody)?
158+
FUN (NL* typeParameters)? (NL* receiverType NL* DOT)? NL* simpleIdentifier
159+
NL* functionValueParameters
160+
(NL* COLON NL* type)?
161+
(NL* typeConstraints)?
162+
(NL* functionBody)?
163163
;
164164

165165
functionBody
@@ -177,12 +177,12 @@ multiVariableDeclaration
177177

178178
propertyDeclaration
179179
: modifiers? (VAL | VAR)
180-
(NL* typeParameters)?
181-
(NL* receiverType NL* DOT)?
182-
(NL* (multiVariableDeclaration | variableDeclaration))
183-
(NL* typeConstraints)?
184-
(NL* (ASSIGNMENT NL* expression | propertyDelegate))?
185-
(NL+ SEMICOLON)? NL* (getter? (NL* semi? setter)? | setter? (NL* semi? getter)?)
180+
(NL* typeParameters)?
181+
(NL* receiverType NL* DOT)?
182+
(NL* (multiVariableDeclaration | variableDeclaration))
183+
(NL* typeConstraints)?
184+
(NL* (ASSIGNMENT NL* expression | propertyDelegate))?
185+
(NL+ SEMICOLON)? NL* (getter? (NL* semi? setter)? | setter? (NL* semi? getter)?)
186186
;
187187

188188
propertyDelegate
@@ -191,12 +191,12 @@ propertyDelegate
191191

192192
getter
193193
: modifiers? GET
194-
| modifiers? GET NL* LPAREN NL* RPAREN (NL* COLON NL* type)? NL* functionBody
194+
(NL* LPAREN NL* RPAREN (NL* COLON NL* type)? NL* functionBody)?
195195
;
196196

197197
setter
198198
: modifiers? SET
199-
| modifiers? SET NL* LPAREN NL* parameterWithOptionalType (NL* COMMA)? NL* RPAREN (NL* COLON NL* type)? NL* functionBody
199+
(NL* LPAREN NL* parameterWithOptionalType (NL* COMMA)? NL* RPAREN (NL* COLON NL* type)? NL* functionBody)?
200200
;
201201

202202
parametersWithOptionalType
@@ -213,18 +213,17 @@ parameter
213213

214214
objectDeclaration
215215
: modifiers? OBJECT
216-
NL* simpleIdentifier
217-
(NL* COLON NL* delegationSpecifiers)?
218-
(NL* classBody)?
216+
NL* simpleIdentifier
217+
(NL* COLON NL* delegationSpecifiers)?
218+
(NL* classBody)?
219219
;
220220

221221
secondaryConstructor
222222
: modifiers? CONSTRUCTOR NL* functionValueParameters (NL* COLON NL* constructorDelegationCall)? NL* block?
223223
;
224224

225225
constructorDelegationCall
226-
: THIS NL* valueArguments
227-
| SUPER NL* valueArguments
226+
: (THIS | SUPER) NL* valueArguments
228227
;
229228

230229
// SECTION: enumClasses
@@ -244,11 +243,7 @@ enumEntry
244243
// SECTION: types
245244

246245
type
247-
: typeModifiers?
248-
( parenthesizedType
249-
| nullableType
250-
| typeReference
251-
| functionType)
246+
: typeModifiers? (parenthesizedType | nullableType | typeReference | functionType)
252247
;
253248

254249
typeReference
@@ -274,7 +269,8 @@ simpleUserType
274269
;
275270

276271
typeProjection
277-
: typeProjectionModifiers? type | MULT
272+
: typeProjectionModifiers? type
273+
| MULT
278274
;
279275

280276
typeProjectionModifiers
@@ -299,15 +295,11 @@ parenthesizedType
299295
;
300296

301297
receiverType
302-
: typeModifiers?
303-
( parenthesizedType
304-
| nullableType
305-
| typeReference)
298+
: typeModifiers? (parenthesizedType | nullableType | typeReference)
306299
;
307300

308301
parenthesizedUserType
309-
: LPAREN NL* userType NL* RPAREN
310-
| LPAREN NL* parenthesizedUserType NL* RPAREN
302+
: LPAREN NL* (userType | parenthesizedUserType) NL* RPAREN
311303
;
312304

313305
// SECTION: statements
@@ -317,11 +309,7 @@ statements
317309
;
318310

319311
statement
320-
: (label | annotation)*
321-
( declaration
322-
| assignment
323-
| loopStatement
324-
| expression)
312+
: (label | annotation)* ( declaration | assignment | loopStatement | expression)
325313
;
326314

327315
label
@@ -344,26 +332,26 @@ loopStatement
344332
;
345333

346334
forStatement
347-
: FOR NL* LPAREN annotation* (variableDeclaration | multiVariableDeclaration) IN expression RPAREN NL* controlStructureBody?
335+
: FOR NL* LPAREN annotation* (variableDeclaration | multiVariableDeclaration)
336+
IN expression RPAREN NL* controlStructureBody?
348337
;
349338

350339
whileStatement
351-
: WHILE NL* LPAREN expression RPAREN NL* controlStructureBody
352-
| WHILE NL* LPAREN expression RPAREN NL* SEMICOLON
340+
: WHILE NL* LPAREN expression RPAREN NL* (controlStructureBody | SEMICOLON)
353341
;
354342

355343
doWhileStatement
356344
: DO NL* controlStructureBody? NL* WHILE NL* LPAREN expression RPAREN
357345
;
358346

359347
assignment
360-
: directlyAssignableExpression ASSIGNMENT NL* expression
361-
| assignableExpression assignmentAndOperator NL* expression
348+
: (directlyAssignableExpression ASSIGNMENT | assignableExpression assignmentAndOperator) NL* expression
362349
;
363350

364351
semi
365352
: (SEMICOLON | NL) NL*
366-
| EOF;
353+
| EOF
354+
;
367355

368356
semis
369357
: (SEMICOLON | NL)+
@@ -439,8 +427,7 @@ unaryPrefix
439427
;
440428

441429
postfixUnaryExpression
442-
: primaryExpression
443-
| primaryExpression postfixUnarySuffix+
430+
: primaryExpression postfixUnarySuffix*
444431
;
445432

446433
postfixUnarySuffix
@@ -462,7 +449,8 @@ parenthesizedDirectlyAssignableExpression
462449
;
463450

464451
assignableExpression
465-
: prefixUnaryExpression | parenthesizedAssignableExpression
452+
: prefixUnaryExpression
453+
| parenthesizedAssignableExpression
466454
;
467455

468456
parenthesizedAssignableExpression
@@ -484,8 +472,7 @@ navigationSuffix
484472
;
485473

486474
callSuffix
487-
: typeArguments? valueArguments? annotatedLambda
488-
| typeArguments? valueArguments
475+
: typeArguments? (valueArguments? annotatedLambda | valueArguments)
489476
;
490477

491478
annotatedLambda
@@ -497,8 +484,7 @@ typeArguments
497484
;
498485

499486
valueArguments
500-
: LPAREN NL* RPAREN
501-
| LPAREN NL* valueArgument (NL* COMMA NL* valueArgument)* (NL* COMMA)? NL* RPAREN
487+
: LPAREN NL* (valueArgument (NL* COMMA NL* valueArgument)* (NL* COMMA)? NL*)? RPAREN
502488
;
503489

504490
valueArgument
@@ -527,8 +513,7 @@ parenthesizedExpression
527513
;
528514

529515
collectionLiteral
530-
: LSQUARE NL* expression (NL* COMMA NL* expression)* (NL* COMMA)? NL* RSQUARE
531-
| LSQUARE NL* RSQUARE
516+
: LSQUARE NL* (expression (NL* COMMA NL* expression)* (NL* COMMA)? NL*)? RSQUARE
532517
;
533518

534519
literalConstant
@@ -577,8 +562,7 @@ multiLineStringExpression
577562
;
578563

579564
lambdaLiteral
580-
: LCURL NL* statements NL* RCURL
581-
| LCURL NL* lambdaParameters? NL* ARROW NL* statements NL* RCURL
565+
: LCURL NL* (lambdaParameters? NL* ARROW NL*)? statements NL* RCURL
582566
;
583567

584568
lambdaParameters
@@ -592,11 +576,11 @@ lambdaParameter
592576

593577
anonymousFunction
594578
: FUN
595-
(NL* type NL* DOT)?
596-
NL* parametersWithOptionalType
597-
(NL* COLON NL* type)?
598-
(NL* typeConstraints)?
599-
(NL* functionBody)?
579+
(NL* type NL* DOT)?
580+
NL* parametersWithOptionalType
581+
(NL* COLON NL* type)?
582+
(NL* typeConstraints)?
583+
(NL* functionBody)?
600584
;
601585

602586
functionLiteral
@@ -605,8 +589,7 @@ functionLiteral
605589
;
606590

607591
objectLiteral
608-
: OBJECT NL* COLON NL* delegationSpecifiers NL* classBody
609-
| OBJECT NL* classBody
592+
: OBJECT NL* (COLON NL* delegationSpecifiers NL*)? classBody
610593
;
611594

612595
thisExpression
@@ -620,8 +603,10 @@ superExpression
620603
;
621604

622605
ifExpression
623-
: IF NL* LPAREN NL* expression NL* RPAREN NL* (controlStructureBody | SEMICOLON)
624-
| IF NL* LPAREN NL* expression NL* RPAREN NL* controlStructureBody? NL* SEMICOLON? NL* ELSE NL* (controlStructureBody | SEMICOLON)
606+
: IF NL* LPAREN NL* expression NL* RPAREN NL*
607+
( controlStructureBody
608+
| controlStructureBody? NL* SEMICOLON? NL* ELSE NL* (controlStructureBody | SEMICOLON)
609+
| SEMICOLON)
625610
;
626611

627612
whenSubject
@@ -666,12 +651,14 @@ finallyBlock
666651
jumpExpression
667652
: THROW NL* expression
668653
| (RETURN | RETURN_AT) expression?
669-
| CONTINUE | CONTINUE_AT
670-
| BREAK | BREAK_AT
654+
| CONTINUE
655+
| CONTINUE_AT
656+
| BREAK
657+
| BREAK_AT
671658
;
672659

673660
callableReference
674-
: (receiverType? NL* COLONCOLON NL* (simpleIdentifier | CLASS))
661+
: receiverType? NL* COLONCOLON NL* (simpleIdentifier | CLASS)
675662
;
676663

677664
assignmentAndOperator
@@ -697,15 +684,18 @@ comparisonOperator
697684
;
698685

699686
inOperator
700-
: IN | NOT_IN
687+
: IN
688+
| NOT_IN
701689
;
702690

703691
isOperator
704-
: IS | NOT_IS
692+
: IS
693+
| NOT_IS
705694
;
706695

707696
additiveOperator
708-
: ADD | SUB
697+
: ADD
698+
| SUB
709699
;
710700

711701
multiplicativeOperator
@@ -739,7 +729,9 @@ excl
739729
;
740730

741731
memberAccessOperator
742-
: DOT | safeNav | COLONCOLON
732+
: DOT
733+
| safeNav
734+
| COLONCOLON
743735
;
744736

745737
safeNav
@@ -772,7 +764,8 @@ typeModifiers
772764
;
773765

774766
typeModifier
775-
: annotation | SUSPEND NL*
767+
: annotation
768+
| SUSPEND NL*
776769
;
777770

778771
classModifier
@@ -851,13 +844,11 @@ annotation
851844
;
852845

853846
singleAnnotation
854-
: annotationUseSiteTarget NL* unescapedAnnotation
855-
| (AT_NO_WS | AT_PRE_WS) unescapedAnnotation
847+
: (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) unescapedAnnotation
856848
;
857849

858850
multiAnnotation
859-
: annotationUseSiteTarget NL* LSQUARE unescapedAnnotation+ RSQUARE
860-
| (AT_NO_WS | AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE
851+
: (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE
861852
;
862853

863854
annotationUseSiteTarget
@@ -871,7 +862,8 @@ unescapedAnnotation
871862

872863
// SECTION: identifiers
873864

874-
simpleIdentifier: Identifier
865+
simpleIdentifier
866+
: Identifier
875867
| ABSTRACT
876868
| ANNOTATION
877869
| BY

0 commit comments

Comments
 (0)