-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.iggy
More file actions
853 lines (684 loc) · 23 KB
/
Copy pathjava.iggy
File metadata and controls
853 lines (684 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
grammar Java
CompilationUnit
= OrdinaryCompilationUnit
| ModularCompilationUnit
OrdinaryCompilationUnit
= PackageDeclaration? ImportDeclaration* TypeDeclaration*
ModularCompilationUnit
= ImportDeclaration* ModuleDeclaration
ModuleDeclaration
= Annotation* "open"? "module" QualifiedIdentifier "{" ModuleDirective* "}"
ModuleDirective
= "requires" RequiresModifier* QualifiedIdentifier ";" #Requires
| "exports" QualifiedIdentifier ("to" { QualifiedIdentifier "," }+)? ";" #Exports
| "opens" QualifiedIdentifier ("to" { QualifiedIdentifier "," }+)? ";" #Opens
| "uses" TypeName ";" #Uses
| "provides" TypeName "with" { TypeName "," }+ ";" #Provides
RequiresModifier
= "transitive"
| "static"
PackageDeclaration
= Annotation* "package" QualifiedIdentifier ";"
// JLS 14 §7.5 defines four import forms, which differ in what each may name. A
// TypeName ends in a TypeIdentifier, so `import yield;` is not valid. The qualifier of
// a non-static on-demand import and the member of a single static import are ordinary
// identifiers, so `import yield.*;` and `import static A.yield;` are valid.
ImportDeclaration
= "import" TypeName ";" #SingleType
| "import" QualifiedIdentifier "." "*" ";" #TypeImportOnDemand
| "import" "static" TypeName "." Identifier ";" #SingleStaticImport
| "import" "static" TypeName "." "*" ";" #StaticImportOnDemand
TypeDeclaration
= ClassDeclaration
| InterfaceDeclaration
| ";"
ClassDeclaration
= NormalClassDeclaration
| EnumDeclaration
NormalClassDeclaration
= ClassModifier* "class" TypeIdentifier TypeParameters? ("extends" ClassType)?
("implements" ClassTypeList)? ClassBody
EnumDeclaration
= ClassModifier* "enum" TypeIdentifier ("implements" ClassTypeList)? EnumBody
InterfaceDeclaration
= NormalInterfaceDeclaration
| AnnotationTypeDeclaration
NormalInterfaceDeclaration
= InterfaceModifier* "interface" TypeIdentifier TypeParameters?
("extends" ClassTypeList)? InterfaceBody
AnnotationTypeDeclaration
= InterfaceModifier* "@" "interface" TypeIdentifier AnnotationTypeBody
ClassBody
= "{" ClassBodyDeclaration* "}"
ClassBodyDeclaration
= Initializer
| ConstructorDeclaration
| FieldDeclaration
| MethodDeclaration
| ClassDeclaration
| InterfaceDeclaration
| ";"
MethodDeclaration
= MethodModifier* (TypeParameters Annotation*)? Result MethodDeclarator
Throws? MethodBody
MethodDeclarator
= Identifier "(" FormalParameterList? ")" (Annotation* "[" "]")*
FormalParameterList
= ReceiverParameter ("," (FormalParameter ",")* LastFormalParameter)?
| (FormalParameter ",")* LastFormalParameter
FormalParameter
= VariableModifier* UnannType VariableDeclaratorId
LastFormalParameter
= VariableModifier* UnannType Annotation* "..." VariableDeclaratorId
| FormalParameter
ReceiverParameter
= Annotation* UnannType (Identifier ".")? "this"
Result
= UnannType
| "void"
Throws
= "throws" { ClassType "," }+
MethodBody
= Block
| ";"
ConstructorDeclaration
= ConstructorModifier* TypeParameters? TypeIdentifier "(" FormalParameterList?
")" Throws? ConstructorBody
ConstructorBody
= "{" ExplicitConstructorInvocation? BlockStatement* "}"
ExplicitConstructorInvocation
= constructorInvocation:NonWildTypeArguments? "this" Arguments ";"
| superConstructorInvocation:(Primary ".")? NonWildTypeArguments? "super"
Arguments ";"
TypeList
= { Type "," }+
ClassTypeList
= { ClassType "," }+
TypeParameters
= "<" { TypeParameter "," }+ ">"
TypeParameter
= Annotation* TypeIdentifier TypeBound?
TypeBound
= "extends" ReferenceType ("&" ReferenceType)*
Initializer
= "static"? Block
EnumBody
= "{" { EnumConstant "," }* ","? EnumBodyDeclarations? "}"
EnumConstant
= Annotation* Identifier Arguments? ClassBody?
Arguments
= "(" { Expression "," }* ")"
EnumBodyDeclarations
= ";" ClassBodyDeclaration*
Block
= "{" BlockStatement* "}"
BlockStatement
= LocalVariableDeclarationStatement
| ClassDeclaration
| Statement
LocalVariableDeclarationStatement
= VariableModifier* LocalVariableType { VariableDeclarator "," }+ ";"
LocalVariableType
= UnannType
| "var"
FieldDeclaration
= FieldModifier* UnannType { VariableDeclarator "," }+ ";"
VariableDeclarator
= VariableDeclaratorId ("=" VariableInitializer)?
VariableDeclaratorId
= Identifier (Annotation* "[" "]")*
VariableInitializer
= ArrayInitializer
| Expression
ArrayInitializer
= "{" { VariableInitializer "," }* ","? "}"
Annotation
= "@" TypeName Values?
Values
= "(" AnnotationElement? ")"
AnnotationElement
= { ElementValuePair "," }+
| { ElementValue "," }+
ElementValuePair
= Identifier "=" ElementValue
ElementValue
// !Assignment `@A(x = y)` should be parsed as an ElementValuePair, not as
// an ElementValue holding the assignment `x = y`. The exclusion
// drops the Expression's Assignment alternative, so only the
// first derivation survives.
= Expression!Assignment
| Annotation
| ElementValueArrayInitializer
ElementValueArrayInitializer
= "{" { ElementValue "," }* ","? "}"
InterfaceBody
= "{" InterfaceMemberDeclaration* "}"
InterfaceMemberDeclaration
= ConstantDeclaration
| InterfaceMethodDeclaration
| ClassDeclaration
| InterfaceDeclaration
| ";"
ConstantDeclaration
= ConstantModifier* UnannType { VariableDeclarator "," }+ ";"
InterfaceMethodDeclaration
= InterfaceMethodModifier* (TypeParameters Annotation*)? Result
MethodDeclarator Throws? (Block | ";")
AnnotationTypeBody
= "{" AnnotationTypeElementDeclaration* "}"
AnnotationTypeElementDeclaration
= AnnotationMethodDeclaration
| ConstantDeclaration
| ClassDeclaration
| InterfaceDeclaration
| ";"
AnnotationMethodDeclaration
= InterfaceMethodModifier* UnannType Identifier "(" ")" (Annotation* "[" "]")*
DefaultValue? ";"
DefaultValue
= "default" ElementValue
ClassModifier
= Annotation
| "public"
| "protected"
| "private"
| "abstract"
| "static"
| "final"
| "strictfp"
ConstructorModifier
= Annotation
| "public"
| "protected"
| "private"
InterfaceModifier
= Annotation
| "public"
| "protected"
| "private"
| "abstract"
| "static"
| "strictfp"
ConstantModifier
= Annotation
| "public"
| "static"
| "final"
InterfaceMethodModifier
= Annotation
| "public"
| "abstract"
| "default"
| "static"
| "strictfp"
| "private"
FieldModifier
= Annotation
| "public"
| "protected"
| "private"
| "static"
| "final"
| "transient"
| "volatile"
MethodModifier
= Annotation
| "public"
| "protected"
| "private"
| "abstract"
| "static"
| "final"
| "synchronized"
| "native"
| "strictfp"
VariableModifier
= Annotation
| "final"
Statement
= Block #Block
| ";" #Empty
| StatementExpression ";" #Expression
| "assert" Expression (":" Expression)? ";" #Assert
| "switch" "(" Expression ")" SwitchBlock #Switch
| "do" Statement "while" "(" Expression ")" ";" #Do
| "break" Identifier? ";" #Break
| "continue" Identifier? ";" #Continue
| "return" Expression? ";" #Return
| "synchronized" "(" Expression ")" Block #Synchronized
| "throw" Expression ";" #Throw
| "yield" Expression ";" #Yield
| "try" Block CatchClause+ #Try
| "try" Block CatchClause* Finally #TryFinally
| "try" ResourceSpecification Block CatchClause* Finally? #TryWithResourcesStmt
| Identifier ":" Statement #Label
| "if" "(" Expression ")" Statement !>>> Else #If
| "if" "(" Expression ")" Statement Else Statement #IfElse
| "while" "(" Expression ")" Statement #While
| "for" "(" ForControl ")" Statement #For
StatementExpression
// Each exclusion removes a derivation that would lead to ambiguity:
// !Comparison `Map<K> m;` declares m of the generic type `Map<K>`, not the
// comparisons `(Map < K) > m`
// !SwitchExpression `switch (d) { case 1: f(); };` is a switch statement and an
// empty statement, not one expression statement
// !Additive `yield -1;` is a yield statement, not the sum `yield - 1`
= Expression!Comparison!SwitchExpression!Additive
SwitchBlock
= "{" SwitchRule+ "}" #Rules
| "{" SwitchBlockStatementGroup* (SwitchLabel ":")* "}" #Groups
SwitchRule
= SwitchLabel "->" Expression ";" #Expression
| SwitchLabel "->" Block #Block
| SwitchLabel "->" "throw" Expression ";" #Throw
SwitchBlockStatementGroup
= (SwitchLabel ":")+ BlockStatement+
SwitchLabel
= "case" { CaseConstant "," }+ #Case
| "default" #Default
CaseConstant
// !Lambda `case A -> B -> C;` should be parsed as a SwitchRule with the lambda
// `B -> C` as its expression, not with its label parsed as the lambda
// `A -> B`. The exclusion drops the Expression's Lambda alternative, so
// only the first derivation survives, through SwitchRule's first
// alternative.
// !Assignment An assignment as the case constant, as in `case a = 1:`, is
// not valid. This is not a disambiguation, since that input is not
// ambiguous. It is a deliberate language reduction: JLS 14 §14.11
// defines a case constant as a conditional expression, which an
// assignment is not.
= Expression!Lambda!Assignment
ForControl
= ForInit? ";" Expression? ";" ForUpdate? #Traditional
| VariableModifier* LocalVariableType VariableDeclaratorId ":" Expression #Enhanced
CatchClause
= "catch" "(" VariableModifier* CatchType Identifier ")" Block
CatchType
= UnannClassType ("|" ClassType)*
Finally
= "finally" Block
ResourceSpecification
= "(" { Resource ";" }+ ";"? ")"
Resource
= VariableModifier* (UnannReferenceType | "var") VariableDeclaratorId "="
Expression
| QualifiedIdentifier
| "this" "." Identifier
ForInit
= expressions:{ StatementExpression "," }+
| variableDecl:VariableModifier* LocalVariableType { VariableDeclarator "," }+
ForUpdate
= { Expression "," }+
Expression
= Primary #Primary
| "switch" "(" Expression ")" SwitchBlock #SwitchExpression
| MethodInvocation #MethodInvocation
| MarkedClassType "::" TypeArguments? Identifier #TypeMethodRef
| ClassType "::" TypeArguments? "new" #ConstructorRef
| ArrayType "::" "new" #ArrayConstructorRef
| ArrayType "::" TypeArguments? Identifier #ArrayMethodRef
| "super" "::" TypeArguments? Identifier #SuperMethodRef
| TypeName "." "super" "::" TypeArguments? Identifier #QualifiedSuperMethodRef
| "new" (ClassInstanceCreationExpression | ArrayCreationExpression) #New
// !InstanceOf `a instanceof Foo.Bar` should be parsed as one InstanceOf over
// the qualified type `Foo.Bar`, not as `.Bar` selected from
// `a instanceof Foo`. Dropping the InstanceOf alternative leaves
// one derivation.
// !SwitchExpression A language reduction, not a disambiguation. JLS 14 §19 makes
// SwitchExpression an alternative of UnaryExpressionNotPlusMinus
// rather than of Primary or PostfixExpression, so a postfix
// operator cannot follow a switch expression:
// `switch (d) { ... }.f` is not valid, and
// `(switch (d) { ... }).f` is, because a parenthesized expression
// is a Primary. The exclusion applies to all four alternatives
// below.
> Expression!InstanceOf!SwitchExpression "." Selector #FieldAccess
| Expression!SwitchExpression "[" Expression "]" #ArrayAccess
| Expression!SwitchExpression ("++" | "--") #Postfix
| Expression!SwitchExpression "::" TypeArguments? Identifier #MethodRef
> ("+" !>> Plus | "-" !>> Minus | "++" | "--") Expression #Prefix
| ("!" | "~") Expression #Complement
| "(" PrimitiveType ")" Expression #PrimitiveCast
// !Prefix `(a) - b` derives both as a subtraction and as a reference cast
// of `-b`. Dropping the Prefix alternative keeps the subtraction,
// which is what JLS 14 §15.16 requires: a reference cast takes a
// unary expression that is not prefixed by + or -. The Complement
// alternative is untouched, so `(Integer) ~x` is still a cast.
| "(" { ReferenceType "&" }+ ")" Expression!Prefix #RefCast
> left Expression ("*" | "/" | "%") Expression
> left Expression ("+" | "-") !>> Plus !>> Minus Expression #Additive
> left Expression ("<<" | ">>" | ">>>") Expression
> left Expression ("<" | ">" | "<=" | ">=") Expression #Comparison
> Expression "instanceof" Type #InstanceOf
> left Expression ("==" | "!=") Expression
> left Expression "&" Expression
> left Expression "^" Expression
> left Expression "|" Expression
> left Expression "&&" Expression
> left Expression "||" Expression
> right Expression "?" Expression ":" Expression #Conditional
// !Comparison A language reduction, not a disambiguation. `a < b = c`
// derives once and the exclusion deletes it: JLS 14 §15.26 takes
// the left side of an assignment from the expression names,
// field accesses, and array accesses, and a comparison is none
// of those.
> right Expression!Comparison AssignmentOperator Expression #Assignment
> Lambda #Lambda
Primary
= Literal #Literal
| (TypeName ".")? "this" #This
| "super" SuperSuffix #Super
| Identifier #Identifier
| (Type | "void") "." "class" #Type
| "(" Expression ")" #Expression
QualifiedIdentifier
= { Identifier "." }+
// JLS 14 §6.5 takes the last component of a type name from TypeIdentifier and the
// qualifier before it from ordinary identifiers, so `yield.Foo` is valid while `@yield`
// and `yield.this` are not.
TypeName
= (Identifier ".")* TypeIdentifier
SuperSuffix
= "." NonWildTypeArguments? Identifier Arguments?
NonWildTypeArguments
= "<" { Type "," }+ ">"
Type
= PrimitiveType
| ReferenceType
PrimitiveType
= Annotation*
("byte" | "short" | "char" | "int" | "long" | "float" | "double" | "boolean")
ReferenceType
= ClassType
| ArrayType
// JLS 14 §4.3 qualifies a class type with either a package name, whose components are
// ordinary identifiers, or another class or interface type, whose components are type
// identifiers. A component with annotations or type arguments is therefore a type
// component, and every component after it is one too, since a package name cannot
// follow a class or interface type. So `yield.Foo` names a type in a package called
// yield, while `yield<T>.Foo` and `A<T>.yield.Foo` do not.
MarkedTypeComponent
= Annotation+ TypeIdentifier TypeArguments?
| TypeIdentifier TypeArguments
MarkedClassType
= (Identifier ".")* MarkedTypeComponent ("." Annotation* TypeIdentifier TypeArguments?)*
ClassType
= (Identifier ".")* TypeIdentifier
| MarkedClassType
ClassTypeToInstantiate
= Annotation* Identifier ("." Annotation* Identifier)* TypeArgumentsOrDiamond?
TypeArguments
= "<" { TypeArgument "," }+ ">"
TypeArgument
= ReferenceType #Simple
| wildCardTypeArgument:Annotation* "?" (("extends" | "super") ReferenceType)? #WildCard
ArrayType
= (ClassType | PrimitiveType) (Annotation* "[" "]")+
UnannType
= UnannPrimitiveType
| UnannReferenceType
UnannPrimitiveType
= "byte"
| "short"
| "char"
| "int"
| "long"
| "float"
| "double"
| "boolean"
UnannReferenceType
= UnannClassType
| UnannArrayType
// An unannotated class type cannot begin with an annotation. A type component at the
// start can therefore be distinguished from a package component only through type
// arguments.
UnannClassType
= (Identifier ".")* TypeIdentifier
| TypeIdentifier TypeArguments ("." Annotation* TypeIdentifier TypeArguments?)*
| (Identifier ".")+ MarkedTypeComponent ("." Annotation* TypeIdentifier TypeArguments?)*
UnannArrayType
= (UnannClassType | UnannPrimitiveType) (Annotation* "[" "]")+
Literal
= IntegerLiteral !>> Dot #Integer
| FloatingPointLiteral #Float
| BooleanLiteral #Boolean
| CharacterLiteral #Character
| StringLiteral #String
| NullLiteral #Null
Selector
= Identifier #Identifier
| NonWildTypeArguments? Identifier Arguments #Method
| "super" SuperSuffix #Super
| "new" TypeArguments? Identifier TypeArgumentsOrDiamond? Arguments ClassBody? #New
MethodInvocation
= UnqualifiedMethodIdentifier Arguments
TypeArgumentsOrDiamond
= "<" ">"
| TypeArguments
ClassInstanceCreationExpression
= TypeArguments? ClassTypeToInstantiate Arguments ClassBody?
ArrayCreationExpression
= (PrimitiveType | ReferenceType) (Annotation* "[" Expression "]")+
(Annotation* "[" "]")* !>> OpenBracket
| (PrimitiveType | ClassType) (Annotation* "[" "]")+ ArrayInitializer
Lambda
= LambdaParameters "->" LambdaBody
LambdaParameters
= "(" LambdaParameterList? ")"
| Identifier
LambdaParameterList
= { LambdaParameter "," }+
| { Identifier "," }+
LambdaParameter
= VariableModifier* LambdaParameterType VariableDeclaratorId
| VariableModifier* UnannType Annotation* "..." VariableDeclaratorId
LambdaParameterType
= UnannType
| "var"
LambdaBody
= Expression
| Block
@Layout
Layout
= (WhiteSpace | Comment)* !>> WhiteSpace !>> Comment
@Regex
HexDigit = [0-9a-fA-F]
@Regex
IntegerLiteral
= DecimalIntegerLiteral
| HexIntegerLiteral
| OctalIntegerLiteral
| BinaryIntegerLiteral
@Regex
FloatingPointLiteral
= DecimalFloatingPointLiteral
| HexadecimalFloatingPointLiteral
@Regex
BooleanLiteral
= "true"
| "false"
@Regex
CharacterLiteral = ['] (SingleCharacter | EscapeSequence) [']
@Regex
DecimalIntegerLiteral = ([0] | ([1-9] (Digits? | ([_]+ Digits)))) [lL]?
@Regex
StringLiteral = ["] StringCharacter* ["]
@Regex
NullLiteral = "null"
@Regex
Dot = "."
@Regex
HexIntegerLiteral = [0] [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?
@Regex
OctalIntegerLiteral = [0] [_]* [0-7] ([0-7_]* [0-7])? [lL]?
@Regex
BinaryIntegerLiteral = [0] [bB] [01] ([01_]* [01])? [lL]?
@Regex
HexadecimalFloatingPointLiteral
= [0] [xX] ((HexDigits [.]?) | (HexDigits? [.] HexDigits)) [pP] Sign? Digits
FloatTypeSuffix?
@Regex
HexDigits = HexDigit (HexDigitOrUnderscore* HexDigit)?
@Regex
HexDigitOrUnderscore = [0-9a-fA-F_]
@Regex
DecimalFloatingPointLiteral
= ((Digits '.' Digits?) | ('.' Digits)) ExponentPart? FloatTypeSuffix?
| Digits ((ExponentPart FloatTypeSuffix?) | FloatTypeSuffix)
@Regex
ExponentPart = ExponentIndicator SignedInteger
@Regex
ExponentIndicator = [eE]
@Regex
SignedInteger = Sign? Digits
@Regex
Sign = [+\-]
@Regex
Digits = [0-9] ([0-9_]* [0-9])?
@Regex
FloatTypeSuffix = [fFdD]
@Regex
OctalNumeral = [0] [_]* OctalDigits
@Regex
OctalDigits = OctalDigit (OctalDigitOrUnderscore* OctalDigit)?
@Regex
OctalDigit = [0-7]
@Regex
OctalDigitOrUnderscore = [0-7_]
@Regex
SingleCharacter
= ![\\\n\r']
| UnicodeEscape
@Regex
StringCharacter
= ![\\\n\r"]
| UnicodeEscape
| EscapeSequence
@Regex
EscapeSequence
= "\\" [btnfr"'\\]
| "\\" (ZeroToThree? OctalDigit)? OctalDigit
@Regex
UnicodeEscape = [\\] [u]+ HexDigit HexDigit HexDigit HexDigit
@Regex
ZeroToThree = [0-3]
@Regex
AssignmentOperator
= "="
| "+="
| "-="
| "*="
| "/="
| "&="
| "|="
| "^="
| "%="
| "<<="
| ">>="
| ">>>="
// JLS 14 §3.8 takes an identifier from the identifier characters and excludes the
// reserved words, `true`, `false`, and `null`, so none of them is a valid variable name.
@Identifier @Regex
Identifier = IdentifierChars \ Keyword \ BooleanLiteral \ NullLiteral
@Regex
TypeKeyword
= "var"
| "yield"
// JLS 14 §3.8 calls `var` and `yield` restricted identifiers. A TypeIdentifier cannot be
// a restricted identifier, so `class var {}` and `class yield {}` are not valid. The
// restriction is on TypeIdentifier rather than on every identifier of a type name, which
// is why `yield.Foo` is valid. `var` is an ordinary identifier in every other position;
// `yield` is barred from one more, as the next rule says.
@Regex
TypeIdentifier = Identifier \ TypeKeyword
@Regex
Yield = "yield"
// Without the exclusion `yield(x);` has two derivations: a yield statement over `(x)`,
// and a call to a method named yield. JLS 14 §3.8 prohibits an unqualified invocation of
// a method named yield, which leaves one. `this.yield(x)` is valid because `Selector`
// uses plain Identifier.
@Regex
UnqualifiedMethodIdentifier = Identifier \ Yield
@Regex
IdentifierChars = JavaLetter (JavaLetter | JavaLetterOrDigit)*
@Regex
JavaLetter = [A-Za-z$_]
@Regex
JavaLetterOrDigit = [A-Za-z$_0-9]
@Regex
Else = "else" !>> JavaLetterOrDigit
@Regex
OpenBracket = "["
@Regex
Plus = "+"
@Regex
Minus = "-"
@Regex
Keyword
= "abstract"
| "continue"
| "for"
| "new"
| "switch"
| "assert"
| "default"
| "if"
| "package"
| "synchronized"
| "boolean"
| "do"
| "goto"
| "private"
| "this"
| "break"
| "double"
| "implements"
| "protected"
| "throw"
| "byte"
| "else"
| "import"
| "public"
| "throws"
| "case"
| "enum"
| "instanceof"
| "return"
| "transient"
| "catch"
| "extends"
| "int"
| "short"
| "try"
| "char"
| "final"
| "interface"
| "static"
| "void"
| "class"
| "finally"
| "long"
| "strictfp"
| "volatile"
| "const"
| "float"
| "native"
| "super"
| "while"
| "_"
@Regex
WhiteSpace = [\ \t\f\r\n]
@Regex
Comment
= TraditionalComment
| EndOfLineComment
@Regex
CommentChar
= [/]
| [*]* ![/*]
@Regex
TraditionalComment = "/*" CommentChar* [*]+ "/"
// JLS 14 §3.7 ends a line comment at a line terminator or at the end of the input,
// so the terminator is not part of the comment and a file may end in one.
@Regex
EndOfLineComment = "//" ![\r\n]*