Constant tree_sitter_java::GRAMMAR [−][src]
pub const GRAMMAR: &'static str = "const DIGITS = token(sep1(/[0-9]+/, /_+/))\nconst HEX_DIGITS = token(sep1(/[A-Fa-f0-9]+/, \'_\'))\nconst PREC = {\n COMMA: -1,\n DECLARATION: 1,\n COMMENT: 1,\n ASSIGN: 0,\n OBJECT: 1,\n TERNARY: 1,\n OR: 2,\n AND: 3,\n PLUS: 4,\n REL: 5,\n TIMES: 6,\n TYPEOF: 7,\n DELETE: 7,\n VOID: 7,\n NOT: 8,\n NEG: 9,\n INC: 10,\n NEW: 11,\n CALL: 12,\n MEMBER: 13,\n CAST: 15,\n};\n\nmodule.exports = grammar({\n name: \'java\',\n\n extras: $ => [\n $.comment,\n /\\s/\n ],\n\n supertypes: $ => [\n $.expression,\n $.declaration,\n $.statement,\n $.primary_expression,\n $._literal,\n $._type,\n $._simple_type,\n $._unannotated_type,\n ],\n\n inline: $ => [\n $._name,\n $._simple_type,\n $._reserved_identifier,\n $._class_body_declaration,\n $._variable_initializer\n ],\n\n conflicts: $ => [\n [$.modifiers, $.annotated_type, $.receiver_parameter],\n [$.modifiers, $.annotated_type, $.module_declaration, $.package_declaration],\n [$._unannotated_type, $.primary_expression, $.inferred_parameters],\n [$._unannotated_type, $.primary_expression],\n [$._unannotated_type, $.primary_expression, $.scoped_type_identifier],\n [$._unannotated_type, $.scoped_type_identifier],\n [$._unannotated_type, $.generic_type],\n [$.generic_type, $.primary_expression],\n ],\n\n word: $ => $.identifier,\n\n rules: {\n program: $ => repeat($.statement),\n\n // Literals\n\n _literal: $ => choice(\n $.decimal_integer_literal,\n $.hex_integer_literal,\n $.octal_integer_literal,\n $.binary_integer_literal,\n $.decimal_floating_point_literal,\n $.hex_floating_point_literal,\n $.true,\n $.false,\n $.character_literal,\n $.string_literal,\n $.null_literal\n ),\n\n decimal_integer_literal: $ => token(seq(\n DIGITS,\n optional(choice(\'l\', \'L\'))\n )),\n\n hex_integer_literal: $ => token(seq(\n choice(\'0x\', \'0X\'),\n HEX_DIGITS,\n optional(choice(\'l\', \'L\'))\n )),\n\n octal_integer_literal: $ => token(seq(\n choice(\'0o\', \'0O\'),\n sep1(/[0-7]+/, \'_\'),\n optional(choice(\'l\', \'L\'))\n )),\n\n binary_integer_literal: $ => token(seq(\n choice(\'0b\', \'0B\'),\n sep1(/[01]+/, \'_\'),\n optional(choice(\'l\', \'L\'))\n )),\n\n decimal_floating_point_literal: $ => token(choice(\n seq(DIGITS, \'.\', optional(DIGITS), optional(seq((/[eE]/), optional(choice(\'-\', \'+\')), DIGITS)), optional(/[fFdD]/)),\n seq(\'.\', DIGITS, optional(seq((/[eE]/), optional(choice(\'-\',\'+\')), DIGITS)), optional(/[fFdD]/)),\n seq(DIGITS, /[eEpP]/, optional(choice(\'-\',\'+\')), DIGITS, optional(/[fFdD]/)),\n seq(DIGITS, optional(seq((/[eE]/), optional(choice(\'-\',\'+\')), DIGITS)), (/[fFdD]/))\n )),\n\n hex_floating_point_literal: $ => token(seq(\n choice(\'0x\', \'0X\'),\n choice(\n seq(HEX_DIGITS, optional(\'.\')),\n seq(optional(HEX_DIGITS), \'.\', HEX_DIGITS)\n ),\n optional(seq(\n /[eEpP]/,\n optional(choice(\'-\',\'+\')),\n DIGITS,\n optional(/[fFdD]/)\n ))\n )),\n\n true: $ => \'true\',\n\n false: $ => \'false\',\n\n character_literal: $ => token(seq(\n \"\'\",\n repeat1(choice(\n /[^\\\\\'\\n]/,\n /\\\\./,\n /\\\\\\n/\n )),\n \"\'\"\n )),\n\n string_literal: $ => token(choice(\n seq(\'\"\', repeat(choice(/[^\\\\\"\\n]/, /\\\\(.|\\n)/)), \'\"\'),\n // TODO: support multiline string literals by debugging the following:\n // seq(\'\"\', repeat(choice(/[^\\\\\"\\n]/, /\\\\(.|\\n)/)), \'\"\', \'+\', /\\n/, \'\"\', repeat(choice(/[^\\\\\"\\n]/, /\\\\(.|\\n)/)))\n )),\n\n null_literal: $ => \'null\',\n\n // Expressions\n\n expression: $ => choice(\n $.assignment_expression,\n $.binary_expression,\n $.instanceof_expression,\n $.lambda_expression,\n $.ternary_expression,\n $.update_expression,\n $.primary_expression,\n $.unary_expression,\n $.cast_expression\n ),\n\n cast_expression: $ => prec(PREC.CAST, seq(\n \'(\',\n sep1(field(\'type\', $._type), \'&\'),\n \')\',\n field(\'value\', $.expression)\n )),\n\n assignment_expression: $ => prec.right(PREC.ASSIGN, seq(\n field(\'left\', choice(\n $.identifier,\n $._reserved_identifier,\n $.field_access,\n $.array_access\n )),\n field(\'operator\', choice(\'=\', \'+=\', \'-=\', \'*=\', \'/=\', \'&=\', \'|=\', \'^=\', \'%=\', \'<<=\', \'>>=\', \'>>>=\')),\n field(\'right\', $.expression)\n )),\n\n binary_expression: $ => choice(\n ...[\n [\'>\', PREC.REL],\n [\'<\', PREC.REL],\n [\'==\', PREC.REL],\n [\'>=\', PREC.REL],\n [\'<=\', PREC.REL],\n [\'!=\', PREC.REL],\n [\'&&\', PREC.AND],\n [\'||\', PREC.OR],\n [\'+\', PREC.PLUS],\n [\'-\', PREC.PLUS],\n [\'*\', PREC.TIMES],\n [\'/\', PREC.TIMES],\n [\'&\', PREC.AND],\n [\'|\', PREC.OR],\n [\'^\', PREC.OR],\n [\'%\', PREC.TIMES],\n [\'<<\', PREC.TIMES],\n [\'>>\', PREC.TIMES],\n [\'>>>\', PREC.TIMES],\n ].map(([operator, precedence]) =>\n prec.left(precedence, seq(\n field(\'left\', $.expression),\n field(\'operator\', operator),\n field(\'right\', $.expression)\n ))\n )),\n\n instanceof_expression: $ => prec(PREC.REL, seq(\n field(\'left\', $.expression),\n \'instanceof\',\n field(\'right\', $._type)\n )),\n\n lambda_expression: $ => seq(\n field(\'parameters\', choice(\n $.identifier, $.formal_parameters, $.inferred_parameters\n )),\n \'->\',\n field(\'body\', choice($.expression, $.block))\n ),\n\n inferred_parameters: $ => seq(\n \'(\',\n commaSep1($.identifier),\n \')\'\n ),\n\n ternary_expression: $ => prec.right(PREC.TERNARY, seq(\n field(\'condition\', $.expression),\n \'?\',\n field(\'consequence\', $.expression),\n \':\',\n field(\'alternative\', $.expression)\n )),\n\n unary_expression: $ => choice(...[\n [\'+\', PREC.NEG],\n [\'-\', PREC.NEG],\n [\'!\', PREC.NOT],\n [\'~\', PREC.NOT],\n ].map(([operator, precedence]) =>\n prec.left(precedence, seq(\n field(\'operator\', operator),\n field(\'operand\', $.expression)\n ))\n )),\n\n update_expression: $ => prec.left(PREC.INC, choice(\n seq($.expression, \'++\'),\n seq($.expression, \'--\'),\n seq(\'++\', $.expression),\n seq(\'--\', $.expression)\n )),\n\n primary_expression: $ => choice(\n $._literal,\n $.class_literal,\n $.this,\n $.identifier,\n $._reserved_identifier,\n $.parenthesized_expression,\n $.object_creation_expression,\n $.field_access,\n $.array_access,\n $.method_invocation,\n $.method_reference,\n $.array_creation_expression\n ),\n\n array_creation_expression: $ => prec.right(seq(\n \'new\',\n field(\'type\', $._simple_type),\n choice(\n seq(\n field(\'dimensions\', repeat1($.dimensions_expr)),\n field(\'dimensions\', optional($.dimensions))\n ),\n seq(\n field(\'dimensions\', $.dimensions),\n field(\'value\', $.array_initializer)\n )\n )\n )),\n\n dimensions_expr: $ => seq(repeat($._annotation), \'[\', $.expression, \']\'),\n\n parenthesized_expression: $ => seq(\'(\', $.expression, \')\'),\n\n class_literal: $ => seq($._unannotated_type, \'.\', \'class\'),\n\n object_creation_expression: $ => choice(\n $._unqualified_object_creation_expression,\n seq($.primary_expression, \'.\', $._unqualified_object_creation_expression)\n ),\n\n _unqualified_object_creation_expression: $ => prec.right(seq(\n \'new\',\n field(\'type_arguments\', optional($.type_arguments)),\n field(\'type\', $._simple_type),\n field(\'arguments\', $.argument_list),\n optional($.class_body)\n )),\n\n field_access: $ => seq(\n field(\'object\', choice($.primary_expression, $.super)),\n optional(seq(\n \'.\',\n $.super\n )),\n \'.\',\n field(\'field\', choice($.identifier, $._reserved_identifier, $.this))\n ),\n\n array_access: $ => seq(\n field(\'array\', $.primary_expression),\n \'[\',\n field(\'index\', $.expression),\n \']\',\n ),\n\n method_invocation: $ => seq(\n choice(\n field(\'name\', choice($.identifier, $._reserved_identifier)),\n seq(\n field(\'object\', choice($.primary_expression, $.super)),\n \'.\',\n optional(seq(\n $.super,\n \'.\'\n )),\n field(\'type_arguments\', optional($.type_arguments)),\n field(\'name\', choice($.identifier, $._reserved_identifier)),\n )\n ),\n field(\'arguments\', $.argument_list)\n ),\n\n argument_list: $ => seq(\'(\', commaSep($.expression), \')\'),\n\n method_reference: $ => seq(\n choice($._type, $.primary_expression, $.super),\n \'::\',\n optional($.type_arguments),\n choice(\'new\', $.identifier)\n ),\n\n type_arguments: $ => seq(\n \'<\',\n commaSep(choice($._type, $.wildcard)),\n \'>\'\n ),\n\n wildcard: $ => seq(\n repeat($._annotation),\n \'?\',\n optional($._wildcard_bounds)\n ),\n\n _wildcard_bounds: $ => choice(\n seq(\'extends\', $._type),\n seq($.super, $._type)\n ),\n\n dimensions: $ => prec.right(repeat1(\n seq(repeat($._annotation), \'[\', \']\')\n )),\n\n // Statements\n\n statement: $ => choice(\n $.declaration,\n $.expression_statement,\n $.labeled_statement,\n $.if_statement,\n $.while_statement,\n $.for_statement,\n $.enhanced_for_statement,\n $.block,\n \';\',\n $.assert_statement,\n $.switch_statement,\n $.do_statement,\n $.break_statement,\n $.continue_statement,\n $.return_statement,\n $.synchronized_statement,\n $.local_variable_declaration,\n $.throw_statement,\n $.try_statement,\n $.try_with_resources_statement\n ),\n\n block: $ => seq(\n \'{\', repeat($.statement), \'}\'\n ),\n\n expression_statement: $ => seq(\n $.expression,\n \';\'\n ),\n\n labeled_statement: $ => seq(\n $.identifier, \':\', $.statement\n ),\n\n assert_statement: $ => choice(\n seq(\'assert\', $.expression, \';\'),\n seq(\'assert\', $.expression, \':\', $.expression, \';\')\n ),\n\n switch_statement: $ => seq(\n \'switch\',\n field(\'condition\', $.parenthesized_expression),\n field(\'body\', $.switch_block)\n ),\n\n switch_block: $ => seq(\n \'{\',\n repeat(choice($.switch_label, $.statement)),\n \'}\'\n ),\n\n switch_label: $ => choice(\n seq(\'case\', $.expression, \':\'),\n seq(\'default\', \':\')\n ),\n\n do_statement: $ => seq(\n \'do\',\n field(\'body\', $.statement),\n \'while\',\n field(\'condition\', $.parenthesized_expression),\n \';\'\n ),\n\n break_statement: $ => seq(\'break\', optional($.identifier), \';\'),\n\n continue_statement: $ => seq(\'continue\', optional($.identifier), \';\'),\n\n return_statement: $ => seq(\n \'return\',\n optional($.expression),\n \';\'\n ),\n\n synchronized_statement: $ => seq(\n \'synchronized\',\n $.parenthesized_expression,\n field(\'body\', $.block)\n ),\n\n throw_statement: $ => seq(\'throw\', $.expression, \';\'),\n\n try_statement: $ => seq(\n \'try\',\n field(\'body\', $.block),\n choice(\n repeat1($.catch_clause),\n seq(repeat($.catch_clause), $.finally_clause)\n )\n ),\n\n catch_clause: $ => seq(\n \'catch\',\n \'(\',\n $.catch_formal_parameter,\n \')\',\n field(\'body\', $.block)\n ),\n\n catch_formal_parameter: $ => seq(\n optional($.modifiers),\n $.catch_type,\n $._variable_declarator_id\n ),\n\n catch_type: $ => sep1($._unannotated_type, \'|\'),\n\n finally_clause: $ => seq(\'finally\', $.block),\n\n try_with_resources_statement: $ => seq(\n \'try\',\n field(\'resources\', $.resource_specification),\n field(\'body\', $.block),\n repeat($.catch_clause),\n optional($.finally_clause)\n ),\n\n resource_specification: $ => seq(\n \'(\', sep1($.resource, \';\'), optional(\';\'), \')\'\n ),\n\n resource: $ => choice(\n seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_id,\n \'=\',\n field(\'value\', $.expression)\n ),\n $.identifier,\n $.field_access\n ),\n\n if_statement: $ => prec.right(seq(\n \'if\',\n field(\'condition\', $.parenthesized_expression),\n field(\'consequence\', $.statement),\n optional(seq(\'else\', field(\'alternative\', $.statement)))\n )),\n\n while_statement: $ => seq(\n \'while\',\n field(\'condition\', $.parenthesized_expression),\n field(\'body\', $.statement)\n ),\n\n for_statement: $ => seq(\n \'for\', \'(\',\n choice(\n field(\'init\', $.local_variable_declaration),\n seq(\n commaSep(field(\'init\', $.expression)),\n \';\'\n )\n ),\n field(\'condition\', optional($.expression)), \';\',\n commaSep(field(\'update\', $.expression)), \')\',\n field(\'body\', $.statement)\n ),\n\n enhanced_for_statement: $ => seq(\n \'for\',\n \'(\',\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_id,\n \':\',\n field(\'value\', $.expression),\n \')\',\n field(\'body\', $.statement)\n ),\n\n // Annotations\n\n _annotation: $ => choice(\n $.marker_annotation,\n $.annotation\n ),\n\n marker_annotation: $ => seq(\n \'@\',\n field(\'name\', $._name)\n ),\n\n annotation: $ => seq(\n \'@\',\n field(\'name\', $._name),\n field(\'arguments\', $.annotation_argument_list)\n ),\n\n annotation_argument_list: $ => seq(\n \'(\',\n choice(\n $._element_value,\n commaSep($.element_value_pair),\n ),\n \')\'\n ),\n\n element_value_pair: $ => seq(\n field(\'key\', $.identifier),\n \'=\',\n field(\'value\', $._element_value)\n ),\n\n _element_value: $ => prec(1, choice(\n $.expression,\n $.element_value_array_initializer,\n $._annotation\n )),\n\n element_value_array_initializer: $ => seq(\n \'{\',\n commaSep($._element_value),\n optional(\',\'),\n \'}\'\n ),\n\n // Declarations\n\n declaration: $ => prec(1, choice(\n $.module_declaration,\n $.package_declaration,\n $.import_declaration,\n $.class_declaration,\n $.interface_declaration,\n $.annotation_type_declaration,\n $.enum_declaration,\n )),\n\n module_declaration: $ => seq(\n repeat($._annotation),\n optional(\'open\'),\n \'module\',\n field(\'name\', $._name),\n field(\'body\', $.module_body)\n ),\n\n module_body: $ => seq(\n \'{\',\n repeat($.module_directive),\n \'}\'\n ),\n\n module_directive: $ => seq(choice(\n seq(\'requires\', repeat($.requires_modifier), $._name),\n seq(\'exports\', $._name, optional(\'to\'), optional($._name), repeat(seq(\',\', $._name))),\n seq(\'opens\', $._name, optional(\'to\'), optional($._name), repeat(seq(\',\', $._name))),\n seq(\'uses\', $._name),\n seq(\'provides\', $._name, \'with\', $._name, repeat(seq(\',\', $._name)))\n ), \';\'),\n\n requires_modifier: $ => choice(\n \'transitive\',\n \'static\'\n ),\n\n package_declaration: $ => seq(\n repeat($._annotation),\n \'package\',\n $._name,\n \';\'\n ),\n\n import_declaration: $ => seq(\n \'import\',\n optional(\'static\'),\n $._name,\n optional(seq(\'.\', $.asterisk)),\n \';\'\n ),\n\n asterisk: $ => \'*\',\n\n enum_declaration: $ => seq(\n optional($.modifiers),\n \'enum\',\n field(\'name\', $.identifier),\n field(\'interfaces\', optional($.super_interfaces)),\n field(\'body\', $.enum_body)\n ),\n\n enum_body: $ => seq(\n \'{\',\n commaSep($.enum_constant),\n optional(\',\'),\n optional($.enum_body_declarations),\n \'}\'\n ),\n\n enum_body_declarations: $ => seq(\n \';\',\n repeat($._class_body_declaration)\n ),\n\n enum_constant: $ => (seq(\n optional($.modifiers),\n field(\'name\', $.identifier),\n field(\'arguments\', optional($.argument_list)),\n field(\'body\', optional($.class_body))\n )),\n\n class_declaration: $ => seq(\n optional($.modifiers),\n \'class\',\n field(\'name\', $.identifier),\n optional(field(\'type_parameters\', $.type_parameters)),\n optional(field(\'superclass\', $.superclass)),\n optional(field(\'interfaces\', $.super_interfaces)),\n field(\'body\', $.class_body)\n ),\n\n modifiers: $ => repeat1(choice(\n $._annotation,\n \'public\',\n \'protected\',\n \'private\',\n \'abstract\',\n \'static\',\n \'final\',\n \'strictfp\',\n \'default\',\n \'synchronized\',\n \'native\',\n \'transient\',\n \'volatile\'\n )),\n\n type_parameters: $ => seq(\n \'<\', commaSep1($.type_parameter), \'>\'\n ),\n\n type_parameter: $ => seq(\n repeat($._annotation),\n $.identifier,\n optional($.type_bound)\n ),\n\n type_bound: $ => seq(\'extends\', $._type, repeat(seq(\'&\', $._type))),\n\n superclass: $ => seq(\n \'extends\',\n $._type\n ),\n\n super_interfaces: $ => seq(\n \'implements\',\n $.interface_type_list\n ),\n\n interface_type_list: $ => seq(\n $._type,\n repeat(seq(\',\', $._type))\n ),\n\n class_body: $ => seq(\n \'{\',\n repeat($._class_body_declaration),\n \'}\'\n ),\n\n _class_body_declaration: $ => choice(\n $.field_declaration,\n $.method_declaration,\n $.class_declaration,\n $.interface_declaration,\n $.annotation_type_declaration,\n $.enum_declaration,\n $.block,\n $.static_initializer,\n $.constructor_declaration,\n \';\'\n ),\n\n static_initializer: $ => seq(\n \'static\',\n $.block\n ),\n\n constructor_declaration: $ => seq(\n optional($.modifiers),\n $._constructor_declarator,\n optional($.throws),\n field(\'body\', $.constructor_body)\n ),\n\n _constructor_declarator: $ => seq(\n field(\'type_parameters\', optional($.type_parameters)),\n field(\'name\', $.identifier),\n field(\'parameters\', $.formal_parameters)\n ),\n\n constructor_body: $ => seq(\n \'{\',\n optional($.explicit_constructor_invocation),\n repeat($.statement),\n \'}\'\n ),\n\n explicit_constructor_invocation: $ => seq(\n choice(\n seq(\n field(\'type_arguments\', optional($.type_arguments)),\n field(\'constructor\', choice($.this, $.super)),\n ),\n seq(\n field(\'object\', choice($.primary_expression)),\n \'.\',\n field(\'type_arguments\', optional($.type_arguments)),\n field(\'constructor\', $.super),\n )\n ),\n field(\'arguments\', $.argument_list),\n \';\'\n ),\n\n _name: $ => choice(\n $.identifier,\n $._reserved_identifier,\n $.scoped_identifier\n ),\n\n scoped_identifier: $ => seq(\n field(\'scope\', $._name),\n \'.\',\n field(\'name\', $.identifier)\n ),\n\n field_declaration: $ => seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_list,\n \';\'\n ),\n\n annotation_type_declaration: $ => seq(\n optional($.modifiers),\n \'@interface\',\n field(\'name\', $.identifier),\n field(\'body\', $.annotation_type_body)\n ),\n\n annotation_type_body: $ => seq(\n \'{\', repeat(choice(\n $.annotation_type_element_declaration,\n $.constant_declaration,\n $.class_declaration,\n $.interface_declaration,\n $.annotation_type_declaration\n )),\n \'}\'\n ),\n\n annotation_type_element_declaration: $ => seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n field(\'name\', $.identifier),\n \'(\', \')\',\n field(\'dimensions\', optional($.dimensions)),\n optional($._default_value),\n \';\'\n ),\n\n _default_value: $ => seq(\n \'default\',\n field(\'value\', $._element_value)\n ),\n\n interface_declaration: $ => seq(\n optional($.modifiers),\n \'interface\',\n field(\'name\', $.identifier),\n field(\'type_parameters\', optional($.type_parameters)),\n optional($.extends_interfaces),\n field(\'body\', $.interface_body)\n ),\n\n extends_interfaces: $ => seq(\n \'extends\',\n $.interface_type_list\n ),\n\n interface_body: $ => seq(\n \'{\',\n repeat(choice(\n $.constant_declaration,\n $.enum_declaration,\n $.method_declaration,\n $.class_declaration,\n $.interface_declaration,\n $.annotation_type_declaration,\n \';\'\n )),\n \'}\'\n ),\n\n constant_declaration: $ => seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_list,\n \';\'\n ),\n\n _variable_declarator_list: $ => commaSep1(\n field(\'declarator\', $.variable_declarator)\n ),\n\n variable_declarator: $ => seq(\n $._variable_declarator_id,\n optional(seq(\'=\', field(\'value\', $._variable_initializer)))\n ),\n\n _variable_declarator_id: $ => seq(\n field(\'name\', choice($.identifier, $._reserved_identifier)),\n field(\'dimensions\', optional($.dimensions))\n ),\n\n _variable_initializer: $ => choice(\n $.expression,\n $.array_initializer\n ),\n\n array_initializer: $ => seq(\n \'{\',\n commaSep($._variable_initializer),\n optional(\',\'),\n \'}\'\n ),\n\n // Types\n\n _type: $ => choice(\n $._unannotated_type,\n $.annotated_type\n ),\n\n _unannotated_type: $ => choice(\n $._simple_type,\n $.array_type\n ),\n\n _simple_type: $ => choice(\n $.void_type,\n $.integral_type,\n $.floating_point_type,\n $.boolean_type,\n alias($.identifier, $.type_identifier),\n $.scoped_type_identifier,\n $.generic_type\n ),\n\n annotated_type: $ => seq(\n repeat1($._annotation),\n $._unannotated_type\n ),\n\n scoped_type_identifier: $ => seq(\n choice(\n alias($.identifier, $.type_identifier),\n $.scoped_type_identifier,\n $.generic_type\n ),\n \'.\',\n repeat($._annotation),\n alias($.identifier, $.type_identifier)\n ),\n\n generic_type: $ => prec.dynamic(10, seq(\n choice(\n alias($.identifier, $.type_identifier),\n $.scoped_type_identifier\n ),\n $.type_arguments\n )),\n\n array_type: $ => seq(\n field(\'element\', $._unannotated_type),\n field(\'dimensions\', $.dimensions)\n ),\n\n integral_type: $ => choice(\n \'byte\',\n \'short\',\n \'int\',\n \'long\',\n \'char\'\n ),\n\n floating_point_type: $ => choice(\n \'float\',\n \'double\'\n ),\n\n boolean_type: $ => \'boolean\',\n\n void_type: $ => \'void\',\n\n _method_header: $ => seq(\n optional(seq(\n field(\'type_parameters\', $.type_parameters),\n repeat($._annotation)\n )),\n field(\'type\', $._unannotated_type),\n $._method_declarator,\n optional($.throws)\n ),\n\n _method_declarator: $ => seq(\n field(\'name\', choice($.identifier, $._reserved_identifier)),\n field(\'parameters\', $.formal_parameters),\n field(\'dimensions\', optional($.dimensions))\n ),\n\n formal_parameters: $ => seq(\n \'(\',\n optional($.receiver_parameter),\n commaSep(choice($.formal_parameter, $.spread_parameter)),\n \')\'\n ),\n\n formal_parameter: $ => seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_id\n ),\n\n receiver_parameter: $ => seq(\n repeat($._annotation),\n $._unannotated_type,\n optional(seq($.identifier, \'.\')),\n $.this\n ),\n\n spread_parameter: $ => seq(\n optional($.modifiers),\n $._unannotated_type,\n \'...\',\n $.variable_declarator\n ),\n\n throws: $ => seq(\n \'throws\', commaSep1($._type)\n ),\n\n local_variable_declaration: $ => seq(\n optional($.modifiers),\n field(\'type\', $._unannotated_type),\n $._variable_declarator_list,\n \';\'\n ),\n\n method_declaration: $ => seq(\n optional($.modifiers),\n $._method_header,\n choice(field(\'body\', $.block), \';\')\n ),\n\n _reserved_identifier: $ => alias(choice(\n \'open\',\n \'module\'\n ), $.identifier),\n\n this: $ => \'this\',\n\n super: $ => \'super\',\n\n // https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-IdentifierChars\n identifier: $ => /[A-Za-z_$][A-Za-z0-9_$]*/,\n\n // http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890\n comment: $ => token(prec(PREC.COMMENT, choice(\n seq(\'//\', /.*/),\n seq(\n \'/*\',\n /[^*]*\\*+([^/*][^*]*\\*+)*/,\n \'/\'\n )\n ))),\n }\n});\n\nfunction sep1 (rule, separator) {\n return seq(rule, repeat(seq(separator, rule)));\n}\n\nfunction commaSep1(rule) {\n return seq(rule, repeat(seq(\',\', rule)))\n}\n\nfunction commaSep(rule) {\n return optional(commaSep1(rule))\n}\n";
The source of the Java tree-sitter grammar description.