compilation_unit = lws, package?, import_declaration*, type_declaration*.
package = -PACKAGE, -name, -SEMI.
-import_declaration = import | static_import.
import = -IMPORT, -name, on_demand?, -SEMI.
static_import = -IMPORT, -STATIC, -name, on_demand?, -SEMI.
-on_demand = dot, '*', ws.
name = -IDENTIFIER, (dot, -IDENTIFIER)*.
-dot = '.', !['0'-'9'; '.'], ws.
-modifiers = (modifier | annotation)*.
modifier = ('public' | 'protected' | 'private' | 'abstract' | 'static' | 'final'
| 'transient' | 'volatile' | 'synchronized' | 'native' | 'strictfp'
| 'default' | 'sealed' | 'non-sealed'), !idchar, ws.
-variable_modifiers = (variable_modifier>modifier | annotation)*.
variable_modifier = 'final', !idchar, ws.
annotation = -AT, name, (-LPAREN, (pair++-COMMA | element_value)?, -RPAREN)?.
pair = @ident>name, ws, -assign, element_value.
-element_value = conditional_expression | annotation | ^element_values>array_initializer.
-element_values = -LBRACE, (element_value++-COMMA)?, -COMMA?, -RBRACE.
type = (primitive | class_type), dim*.
annotated_type = annotation+, (primitive | class_type), dim*.
-any_type = type | annotated_type>type.
primitive = ('boolean' | 'byte' | 'short' | 'char' | 'int' | 'long' | 'float' | 'double'),
!idchar, ws.
-class_type = !restricted, name, class_type_rest?.
-class_type_rest = type_arguments, (-DOT, annotation*, name, class_type_rest?)?
| -DOT, annotation+, name, class_type_rest?.
-restricted = 'var', notid | 'yield', notid | 'record', notid | 'sealed', notid
| 'permits', notid.
dim = annotation*, -LBRACKET, -RBRACKET.
type_arguments = -lt, (type_argument++-COMMA)?, -gt.
-type_argument = any_type | wildcard.
wildcard = -'?', ws, (extends | super)?.
super = -SUPER, any_type.
type_parameters = -lt, type_parameter++-COMMA, -gt.
type_parameter = annotation*, @ident>name, ws, extends?.
extends = -EXTENDS, any_type, (-amp, any_type)*.
-lt = -'<', !['<='], ws.
-gt = -'>', !gt_follow, ws.
-amp = -'&', !['&='], ws.
-assign = -'=', !'=', ws.
-type_declaration = class | interface | enum | record | -SEMI.
class = modifiers, -CLASS, @ident>name, ws, type_parameters?, extends?, implements?,
permits?, body.
interface = modifiers, -INTERFACE, @ident>name, ws, type_parameters?,
^interface_extends>extends?, permits?, body.
enum = modifiers, -ENUM, @ident>name, ws, implements?, ^enum_body>body.
record = modifiers, -'record', !idchar, ws, @ident>name, ws, type_parameters?,
-LPAREN, components?, -RPAREN, implements?, body.
-interface_extends = -EXTENDS, any_type++-COMMA.
implements = -IMPLEMENTS, any_type++-COMMA.
permits = -'permits', !idchar, ws, any_type++-COMMA.
body = -LBRACE, member*, -RBRACE.
-enum_body = -LBRACE, (constant++-COMMA)?, -COMMA?, (-SEMI, member*)?, -RBRACE.
constant = annotation*, @ident>name, ws, arguments?, body?.
-components = (component, -COMMA)*, (component | ^variable_arity_component>component).
component = annotation*, type, @ident>name, ws.
-variable_arity_component = annotation*, type, varargs, @ident>name, ws.
-member = field | method | constructor | compact_constructor | initializer
| class | interface | enum | record | -SEMI.
field = modifiers, type, variable++-COMMA, -SEMI.
variable = @ident>name, ws, dim*, (-assign, variable_initializer)?.
method = modifiers, type_parameters?, (type | void), @ident>name, ws,
-LPAREN, parameters?, -RPAREN, dim*, throws?, (block | -SEMI).
void = -VOID.
constructor = modifiers, type_parameters?, @ident>name, ws,
-LPAREN, parameters?, -RPAREN, throws?, block.
compact_constructor = modifiers, @ident>name, ws, block.
initializer = static?, block.
static = -STATIC.
-parameters = receiver, (-COMMA, parameter_list)? | parameter_list.
-parameter_list = (parameter, -COMMA)*, (parameter | ^variable_arity>parameter).
receiver = variable_modifiers, type, (@ident>outer, ws, -DOT)?, -THIS.
parameter = variable_modifiers, type, @ident>name, ws, dim*.
-variable_arity = variable_modifiers, type, varargs, @ident>name, ws.
varargs = annotation*, -ELLIPSIS.
throws = -THROWS, any_type++-COMMA.
block = -LBRACE, block_statement*, -RBRACE.
-block_statement = local_variable | class | interface | enum | record | statement.
local_variable = variable_modifiers, (type | var), variable++-COMMA, -SEMI.
var = -'var', !idchar, ws.
-statement = block | empty | label | expression_statement | if | assert | switch
| while | do | for | foreach | break | continue | return | throw
| synchronized | try | yield | constructor_call.
empty = -SEMI.
label = @ident>name, ws, -colon, statement.
expression_statement = statement_expression, -SEMI.
if = -IF, -LPAREN, expression, -RPAREN, statement, (else | !kw_else).
else = -ELSE, statement.
-kw_else = 'else', notid.
assert = -ASSERT, expression, (-colon, expression)?, -SEMI.
while = -WHILE, -LPAREN, expression, -RPAREN, statement.
do = -DO, statement, -WHILE, -LPAREN, expression, -RPAREN, -SEMI.
for = -FOR, -LPAREN, for_init?, -SEMI, expression?, -SEMI, for_update?, -RPAREN, statement.
for_init = variable_modifiers, (type | var), variable++-COMMA | statement_expression++-COMMA.
for_update = statement_expression++-COMMA.
foreach = -FOR, -LPAREN, variable_modifiers, (type | var), @ident>name, ws, -colon, expression,
-RPAREN, statement.
break = -BREAK, (@ident>label, ws)?, -SEMI.
continue = -CONTINUE, (@ident>label, ws)?, -SEMI.
return = -RETURN, expression?, -SEMI.
throw = -THROW, expression, -SEMI.
yield = -'yield', !idchar, ws, expression, -SEMI.
synchronized = -SYNCHRONIZED, -LPAREN, expression, -RPAREN, block.
try = -TRY, (resources, block, catch*, finally? | block, (catch+, finally? | finally)).
resources = -LPAREN, resource++-SEMI, -SEMI?, -RPAREN.
resource = variable_modifiers, (type | var), @ident>name, ws, -assign, expression
| primary.
catch = -CATCH, -LPAREN, variable_modifiers, type, (-bar, type)*, @ident>name, ws, -RPAREN, block.
finally = -FINALLY, block.
switch = -SWITCH, -LPAREN, expression, -RPAREN,
-LBRACE, (switch_rule+ | switch_group*, ^last_switch_group>switch_group?), -RBRACE.
switch_rule = (case | default), -arrow, (expression, -SEMI | block | throw).
switch_group = ((case | default), -colon)+, block_statement+.
-last_switch_group = ((case | default), -colon)+.
case = -CASE, conditional_expression++-COMMA.
default = -DEFAULT.
-colon = -':', !':', ws.
-arrow = -'->', ws.
-bar = -'|', !['|='], ws.
-expression = lambda | assignment.
assignment = conditional_expression, (assignment_operator, expression)?.
-assignment_operator = ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | SLASH_ASSIGN
| MOD_ASSIGN | AND_ASSIGN | OR_ASSIGN | XOR_ASSIGN | SHL_ASSIGN
| SHR_ASSIGN | USHR_ASSIGN.
conditional_expression = logical_or, (-question, expression, -colon, (conditional_expression | lambda))?.
-question = -'?', ws.
logical_or = -logical_and | logical_or, OR, logical_and.
logical_and = -bitwise_or | logical_and, AND, bitwise_or.
bitwise_or = -bitwise_xor | bitwise_or, BITOR, bitwise_xor.
bitwise_xor = -bitwise_and | bitwise_xor, CARET, bitwise_and.
bitwise_and = -equality | bitwise_and, BITAND, equality.
equality = -relational | equality, (EQ | NE), relational.
relational = -shift | relational, (LT | GT | LE | GE), shift
| relational, ^INSTANCEOF>instanceof, (type | pattern).
pattern = variable_modifiers, type, @ident>name, ws.
shift = -additive | shift, (SHL | SHR | USHR), additive.
additive = -multiplicative | additive, (PLUS | MINUS), multiplicative.
multiplicative = -unary_level | multiplicative, (STAR | SLASH | PERCENT), unary_level.
SHR = '>>', !['>='], ws.
USHR = '>>>', !'=', ws.
-unary_level = unary | prefix | unary_not_plus_minus.
unary = (PLUS | MINUS), unary_level.
prefix = (INC | DEC), unary_level.
-unary_not_plus_minus = postfix | not_unary>unary | cast | switch.
not_unary = (TILDE | NOT), unary_level.
cast = -LPAREN, ^primitive_cast_type>type, -RPAREN, unary_level
| -LPAREN, ^reference_type>type, (-amp, any_type)*, -RPAREN, (unary_not_plus_minus | lambda).
-primitive_cast_type = primitive.
-reference_type = class_type, dim* | primitive, dim+.
postfix = -primary | new_array | postfix, (INC | DEC).
primary = -primary_start | new_array, (call | field_select | reference) | primary, selector.
-selector = call | field_select | index | reference | outer_new | outer_this | outer_super
| class_selector.
call = -DOT, type_arguments?, @ident>name, ws, arguments.
field_select = -DOT, @ident>name, ws.
index = -LBRACKET, expression, -RBRACKET.
reference = dim*, -COLONCOLON, type_arguments?, (@ident>name, ws | @new_kw>name, ws).
outer_new = -DOT, new.
outer_this = -DOT, -THIS.
outer_super = -DOT, -SUPER.
class_selector = dim*, -DOT, -CLASS.
-new_kw = 'new', !idchar.
-primary_start = IDENTIFIER>name | !yield_word, ^unqualified_call>call | literal
| ^THIS>this | ^SUPER>super | -LPAREN, expression, -RPAREN
| new | class_literal | primitive_reference>method_reference.
-unqualified_call = @ident>name, ws, arguments.
-yield_word = 'yield', notid.
arguments = -LPAREN, (expression++-COMMA)?, -RPAREN.
-literal = INTEGER_LITERAL | FLOATING_POINT_LITERAL | CHARACTER_LITERAL | STRING_LITERAL
| TEXT_BLOCK | BOOLEAN_LITERAL | NULL_LITERAL.
BOOLEAN_LITERAL = ('true' | 'false'), !idchar, ws.
NULL_LITERAL = 'null', !idchar, ws.
class_literal = (^primitive_with_dims>type | ^VOID>void), -DOT, -CLASS.
-primitive_with_dims = primitive, dim*.
primitive_reference = ^primitive_with_dims>type, -COLONCOLON, @new_kw>name, ws.
new = -NEW, type_arguments?, ^new_type>type, arguments, body?.
-new_type = annotation*, class_type.
new_array = -NEW, ^array_element_type>type, dim_expression>dim+, dim*
| -NEW, type, array_initializer.
-array_element_type = primitive | class_type.
dim_expression = annotation*, -LBRACKET, expression, -RBRACKET.
array_initializer = -LBRACE, (variable_initializer++-COMMA)?, -COMMA?, -RBRACE.
-variable_initializer = expression | array_initializer.
lambda = lambda_parameters, -arrow, (expression | block).
-lambda_parameters = ^inferred_parameter>parameter
| -LPAREN, (^inferred_parameter>parameter++-COMMA | lambda_parameter++-COMMA)?, -RPAREN.
-inferred_parameter = @ident>name, ws.
-lambda_parameter = parameter | ^variable_arity>parameter | ^var_parameter>parameter.
-var_parameter = variable_modifiers, var, @ident>name, ws.
-statement_expression = prefix | ^statement_assignment>assignment.
-statement_assignment = postfix, (assignment_operator, expression)?.
constructor_call = (type_arguments?, (^THIS>this | ^SUPER>super)
| primary, -DOT, type_arguments?, ^SUPER>super),
arguments, -SEMI.
-ws = (-hspace | comment)*, (-eol, lws | !wsstart).
-lws = (-[' '; #9; #a; #c; #d; #feff] | leading_comment)*, !wsstart.
-hspace = -[' '; #9; #c; #feff].
-eol = -#a | -#d, -#a | -#d, !#a.
-wsstart = [' '; #9; #a; #c; #d; #feff] | '//' | '/*'.
comment = -'//', ~[#a; #d]*, !~[#a; #d]
| -'/*', comment_char*, -'*/'.
leading_comment = -'//', ~[#a; #d]*, !~[#a; #d]
| -'/*', comment_char*, -'*/'.
-comment_char = ~['*'] | '*', !'/'.
INTEGER_LITERAL = (-hex_numeral | -binary_numeral | -digits), ['lL']?, !numchar, ws.
-numchar = [L; Nd; '_'; '.'].
-digits = ['0'-'9'], (['0'-'9'; '_']*, ['0'-'9'])?.
-hex_digits = hex_digit, ([Nd; 'a'-'f'; 'A'-'F'; '_']*, hex_digit)?.
-hex_digit = ['0'-'9'; 'a'-'f'; 'A'-'F'].
-hex_numeral = '0', ['xX'], hex_digits.
-binary_numeral = '0', ['bB'], ['01'], (['01_']*, ['01'])?.
FLOATING_POINT_LITERAL = (-decimal_float | -hex_float), !numchar, ws.
-decimal_float = digits, '.', digits?, exponent?, float_suffix?
| '.', digits, exponent?, float_suffix?
| digits, exponent, float_suffix?
| digits, float_suffix.
-exponent = ['eE'], ['+-']?, digits.
-float_suffix = ['fFdD'].
-hex_float = '0', ['xX'], (hex_digits, '.'? | hex_digits?, '.', hex_digits),
['pP'], ['+-']?, digits, float_suffix?.
CHARACTER_LITERAL = -"'", (~["'\"; #a; #d] | -escape), -"'", ws.
STRING_LITERAL = !'"""', -'"', (~['"\'; #a; #d] | -escape)*, -'"', ws.
-escape = '\', ( ['btnfrs"\'; "'"]
| octal_escape
| 'u'+, hex_digit, hex_digit, hex_digit, hex_digit).
-octal_escape = ['0'-'3'], ['0'-'7'], ['0'-'7']
| ['0'-'3'], ['0'-'7'], !['0'-'7']
| ['4'-'7'], ['0'-'7']
| ['0'-'7'], !['0'-'7'].
TEXT_BLOCK = -'"""', -[' '; #9; #c]*, -#d?, -#a, (-text_block_char)*, -'"""', ws.
-text_block_char = ~['"\']
| '"', !'""'
| escape
| '\', #d?, #a.
-LPAREN = -'(', ws.
-RPAREN = -')', ws.
-LBRACE = -'{', ws.
-RBRACE = rbrace, ws.
rbrace = -'}'.
-LBRACKET = -'[', ws.
-RBRACKET = -']', ws.
-SEMI = -';', ws.
-COMMA = -',', ws.
-DOT = -'.', !['0'-'9'; '.'], ws.
-ELLIPSIS = -'...', ws.
-AT = -'@', ws.
-COLONCOLON = -'::', ws.
ASSIGN = '=', !'=', ws.
GT = '>', !gt_follow, ws.
-gt_follow = '=' | '>=' | '>>='.
LT = '<', !['<='], ws.
NOT = '!', !'=', ws.
TILDE = '~', ws.
QUESTION = '?', ws.
COLON = ':', !':', ws.
ARROW = '->', ws.
EQ = '==', ws.
GE = '>=', ws.
LE = '<=', ws.
NE = '!=', ws.
AND = '&&', ws.
OR = '||', ws.
INC = '++', ws.
DEC = '--', ws.
PLUS = '+', !['+='], ws.
MINUS = '-', !['-=>'], ws.
STAR = '*', !'=', ws.
SLASH = '/', !['/*='], ws.
BITAND = '&', !['&='], ws.
BITOR = '|', !['|='], ws.
CARET = '^', !'=', ws.
PERCENT = '%', !'=', ws.
SHL = '<<', !'=', ws.
PLUS_ASSIGN = '+=', ws.
MINUS_ASSIGN = '-=', ws.
STAR_ASSIGN = '*=', ws.
SLASH_ASSIGN = '/=', ws.
AND_ASSIGN = '&=', ws.
OR_ASSIGN = '|=', ws.
XOR_ASSIGN = '^=', ws.
MOD_ASSIGN = '%=', ws.
SHL_ASSIGN = '<<=', ws.
SHR_ASSIGN = '>>=', ws.
USHR_ASSIGN = '>>>=', ws.
IDENTIFIER = ident, ws.
-ident = !keyword, idstart, idchar*, !idchar.
-idstart = [L; Nl; Sc; Pc].
-idchar = [L; Nl; Sc; Pc; Nd; Mn; Mc].
-keyword = 'abstract', notid
| 'assert', notid
| 'boolean', notid
| 'break', notid
| 'byte', notid
| 'case', notid
| 'catch', notid
| 'char', notid
| 'class', notid
| 'const', notid
| 'continue', notid
| 'default', notid
| 'do', notid
| 'double', notid
| 'else', notid
| 'enum', notid
| 'extends', notid
| 'final', notid
| 'finally', notid
| 'float', notid
| 'for', notid
| 'goto', notid
| 'if', notid
| 'implements', notid
| 'import', notid
| 'instanceof', notid
| 'int', notid
| 'interface', notid
| 'long', notid
| 'native', notid
| 'new', notid
| 'package', notid
| 'private', notid
| 'protected', notid
| 'public', notid
| 'return', notid
| 'short', notid
| 'static', notid
| 'strictfp', notid
| 'super', notid
| 'switch', notid
| 'synchronized', notid
| 'this', notid
| 'throw', notid
| 'throws', notid
| 'transient', notid
| 'try', notid
| 'void', notid
| 'volatile', notid
| 'while', notid
| 'true', notid
| 'false', notid
| 'null', notid
| '_', notid.
-notid = ~[L; Nl; Sc; Pc; Nd; Mn; Mc].
-ABSTRACT = -'abstract', !idchar, ws.
-ASSERT = -'assert', !idchar, ws.
-BOOLEAN = -'boolean', !idchar, ws.
-BREAK = -'break', !idchar, ws.
-BYTE = -'byte', !idchar, ws.
-CASE = -'case', !idchar, ws.
-CATCH = -'catch', !idchar, ws.
-CHAR = -'char', !idchar, ws.
-CLASS = -'class', !idchar, ws.
-CONST = -'const', !idchar, ws.
-CONTINUE = -'continue', !idchar, ws.
-DEFAULT = -'default', !idchar, ws.
-DO = -'do', !idchar, ws.
-DOUBLE = -'double', !idchar, ws.
-ELSE = -'else', !idchar, ws.
-ENUM = -'enum', !idchar, ws.
-EXTENDS = -'extends', !idchar, ws.
-FINAL = -'final', !idchar, ws.
-FINALLY = -'finally', !idchar, ws.
-FLOAT = -'float', !idchar, ws.
-FOR = -'for', !idchar, ws.
-GOTO = -'goto', !idchar, ws.
-IF = -'if', !idchar, ws.
-IMPLEMENTS = -'implements', !idchar, ws.
-IMPORT = -'import', !idchar, ws.
-INSTANCEOF = -'instanceof', !idchar, ws.
-INT = -'int', !idchar, ws.
-INTERFACE = -'interface', !idchar, ws.
-LONG = -'long', !idchar, ws.
-NATIVE = -'native', !idchar, ws.
-NEW = -'new', !idchar, ws.
-PACKAGE = -'package', !idchar, ws.
-PRIVATE = -'private', !idchar, ws.
-PROTECTED = -'protected', !idchar, ws.
-PUBLIC = -'public', !idchar, ws.
-RETURN = -'return', !idchar, ws.
-SHORT = -'short', !idchar, ws.
-STATIC = -'static', !idchar, ws.
-STRICTFP = -'strictfp', !idchar, ws.
-SUPER = -'super', !idchar, ws.
-SWITCH = -'switch', !idchar, ws.
-SYNCHRONIZED = -'synchronized', !idchar, ws.
-THIS = -'this', !idchar, ws.
-THROW = -'throw', !idchar, ws.
-THROWS = -'throws', !idchar, ws.
-TRANSIENT = -'transient', !idchar, ws.
-TRY = -'try', !idchar, ws.
-VOID = -'void', !idchar, ws.
-VOLATILE = -'volatile', !idchar, ws.
-WHILE = -'while', !idchar, ws.
-TRUE = -'true', !idchar, ws.
-FALSE = -'false', !idchar, ws.
-NULL = -'null', !idchar, ws.
-UNDERSCORE = -'_', !idchar, ws.