Team Ai
Apppublic

aravagarwal/CodeCloakPII

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
grammar.js1301 linesDownload Raw Back to tree-sitter-java
1const DIGITS = token(choice('0', seq(/[1-9]/, optional(seq(optional('_'), sep1(/[0-9]+/, /_+/))))))2const DECIMAL_DIGITS = token(sep1(/[0-9]+/, '_'))3const HEX_DIGITS = token(sep1(/[A-Fa-f0-9]+/, '_'))4const PREC = {5  // https://introcs.cs.princeton.edu/java/11precedence/6  COMMENT: 0,      // //  /*  */7  ASSIGN: 1,       // =  += -=  *=  /=  %=  &=  ^=  |=  <<=  >>=  >>>=8  DECL: 2,9  ELEMENT_VAL: 2,10  TERNARY: 3,      // ?:11  OR: 4,           // ||12  AND: 5,          // &&13  BIT_OR: 6,       // |14  BIT_XOR: 7,      // ^15  BIT_AND: 8,      // &16  EQUALITY: 9,     // ==  !=17  GENERIC: 10,18  REL: 10,         // <  <=  >  >=  instanceof19  SHIFT: 11,       // <<  >>  >>>20  ADD: 12,         // +  -21  MULT: 13,        // *  /  %22  CAST: 14,        // (Type)23  OBJ_INST: 14,    // new24  UNARY: 15,       // ++a  --a  a++  a--  +  -  !  ~25  ARRAY: 16,       // [Index]26  OBJ_ACCESS: 16,  // .27  PARENS: 16,      // (Expression)28  CLASS_LITERAL: 17,  // .29};30 31module.exports = grammar({32  name: 'java',33 34  extras: $ => [35    $.line_comment,36    $.block_comment,37    /\s/38  ],39 40  supertypes: $ => [41    $.expression,42    $.declaration,43    $.statement,44    $.primary_expression,45    $._literal,46    $._type,47    $._simple_type,48    $._unannotated_type,49    $.comment,50    $.module_directive,51  ],52 53  inline: $ => [54    $._name,55    $._simple_type,56    $._class_body_declaration,57    $._variable_initializer,58  ],59 60  conflicts: $ => [61    [$.modifiers, $.annotated_type, $.receiver_parameter],62    [$.modifiers, $.annotated_type, $.module_declaration, $.package_declaration],63    [$._unannotated_type, $.primary_expression, $.inferred_parameters],64    [$._unannotated_type, $.primary_expression],65    [$._unannotated_type, $.primary_expression, $.scoped_type_identifier],66    [$._unannotated_type, $.scoped_type_identifier],67    [$._unannotated_type, $.generic_type],68    [$.generic_type, $.primary_expression],69    [$.expression, $.statement],70    // Only conflicts in switch expressions71    [$.lambda_expression, $.primary_expression],72    [$.inferred_parameters, $.primary_expression],73    [$.argument_list, $.record_pattern_body],74  ],75 76  word: $ => $.identifier,77 78  rules: {79    program: $ => repeat($._toplevel_statement),80 81    _toplevel_statement: $ => choice(82      $.statement,83      $.method_declaration,84    ),85 86    // Literals87 88    _literal: $ => choice(89      $.decimal_integer_literal,90      $.hex_integer_literal,91      $.octal_integer_literal,92      $.binary_integer_literal,93      $.decimal_floating_point_literal,94      $.hex_floating_point_literal,95      $.true,96      $.false,97      $.character_literal,98      $.string_literal,99      $.null_literal100    ),101 102    decimal_integer_literal: $ => token(seq(103      DIGITS,104      optional(choice('l', 'L'))105    )),106 107    hex_integer_literal: $ => token(seq(108      choice('0x', '0X'),109      HEX_DIGITS,110      optional(choice('l', 'L'))111    )),112 113    octal_integer_literal: $ => token(seq(114      choice('0o', '0O', '0'),115      sep1(/[0-7]+/, '_'),116      optional(choice('l', 'L'))117    )),118 119    binary_integer_literal: $ => token(seq(120      choice('0b', '0B'),121      sep1(/[01]+/, '_'),122      optional(choice('l', 'L'))123    )),124 125    decimal_floating_point_literal: $ => token(choice(126      seq(DECIMAL_DIGITS, '.', optional(DECIMAL_DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),127      seq('.', DECIMAL_DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),128      seq(DIGITS, /[eEpP]/, optional(choice('-', '+')), DECIMAL_DIGITS, optional(/[fFdD]/)),129      seq(DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), (/[fFdD]/))130    )),131 132    hex_floating_point_literal: $ => token(seq(133      choice('0x', '0X'),134      choice(135        seq(HEX_DIGITS, optional('.')),136        seq(optional(HEX_DIGITS), '.', HEX_DIGITS)137      ),138      optional(seq(139        /[eEpP]/,140        optional(choice('-', '+')),141        DIGITS,142        optional(/[fFdD]/)143      ))144    )),145 146    true: $ => 'true',147 148    false: $ => 'false',149 150    character_literal: $ => token(seq(151      '\'',152      repeat1(choice(153        /[^\\'\n]/,154        /\\./,155        /\\\n/156      )),157      '\''158    )),159 160    string_literal: $ => choice($._string_literal, $._multiline_string_literal),161    _string_literal: $ => seq(162      '"',163      repeat(choice(164        $.string_fragment,165        $.escape_sequence,166        $.string_interpolation,167      )),168      '"'169    ),170    _multiline_string_literal: $ => seq(171      '"""',172      repeat(choice(173        alias($._multiline_string_fragment, $.multiline_string_fragment),174        $._escape_sequence,175        $.string_interpolation,176      )),177      '"""'178    ),179    // Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156180    // We give names to the token() constructs containing a regexp181    // so as to obtain a node in the CST.182 183    string_fragment: _ => token.immediate(prec(1, /[^"\\]+/)),184    _multiline_string_fragment: _ => choice(185      /[^"\\]+/,186      seq(/"([^"\\]|\\")*/),187    ),188 189    string_interpolation: $ => seq(190      '\\{',191      $.expression,192      '}'193    ),194 195    _escape_sequence: $ => choice(196      prec(2, token.immediate(seq('\\', /[^abfnrtvxu'\"\\\?]/))),197      prec(1, $.escape_sequence)198    ),199    escape_sequence: _ => token.immediate(seq(200      '\\',201      choice(202        /[^xu0-7]/,203        /[0-7]{1,3}/,204        /x[0-9a-fA-F]{2}/,205        /u[0-9a-fA-F]{4}/,206        /u{[0-9a-fA-F]+}/207      ))),208 209    null_literal: _ => 'null',210 211    // Expressions212 213    expression: $ => choice(214      $.assignment_expression,215      $.binary_expression,216      $.instanceof_expression,217      $.lambda_expression,218      $.ternary_expression,219      $.update_expression,220      $.primary_expression,221      $.unary_expression,222      $.cast_expression,223      $.switch_expression,224    ),225 226    cast_expression: $ => prec(PREC.CAST, choice(227      seq(228        '(',229        field('type', $._type),230        ')',231        field('value', $.expression),232      ),233      seq(234        '(',235        sep1(field('type', $._type), '&'),236        ')',237        field('value', choice($.primary_expression, $.lambda_expression)),238      ),239    )),240 241    assignment_expression: $ => prec.right(PREC.ASSIGN, seq(242      field('left', choice(243        $.identifier,244        $._reserved_identifier,245        $.field_access,246        $.array_access247      )),248      field('operator', choice('=', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '%=', '<<=', '>>=', '>>>=')),249      field('right', $.expression)250    )),251 252    binary_expression: $ => choice(253      ...[254        ['>', PREC.REL],255        ['<', PREC.REL],256        ['>=', PREC.REL],257        ['<=', PREC.REL],258        ['==', PREC.EQUALITY],259        ['!=', PREC.EQUALITY],260        ['&&', PREC.AND],261        ['||', PREC.OR],262        ['+', PREC.ADD],263        ['-', PREC.ADD],264        ['*', PREC.MULT],265        ['/', PREC.MULT],266        ['&', PREC.BIT_AND],267        ['|', PREC.BIT_OR],268        ['^', PREC.BIT_XOR],269        ['%', PREC.MULT],270        ['<<', PREC.SHIFT],271        ['>>', PREC.SHIFT],272        ['>>>', PREC.SHIFT],273      ].map(([operator, precedence]) =>274        prec.left(precedence, seq(275          field('left', $.expression),276          field('operator', operator),277          field('right', $.expression)278        ))279      )),280 281    instanceof_expression: $ => prec(PREC.REL, seq(282      field('left', $.expression),283      'instanceof',284      optional('final'),285      choice(286        seq(287          field('right', $._type),288          optional(field('name', choice($.identifier, $._reserved_identifier))),289        ),290        field('pattern', $.record_pattern),291      ),292    )),293 294    lambda_expression: $ => seq(295      field('parameters', choice(296        $.identifier, $.formal_parameters, $.inferred_parameters, $._reserved_identifier297      )),298      '->',299      field('body', choice($.expression, $.block))300    ),301 302    inferred_parameters: $ => seq(303      '(',304      commaSep1(choice($.identifier, $._reserved_identifier)),305      ')'306    ),307 308    ternary_expression: $ => prec.right(PREC.TERNARY, seq(309      field('condition', $.expression),310      '?',311      field('consequence', $.expression),312      ':',313      field('alternative', $.expression)314    )),315 316    unary_expression: $ => choice(...[317      ['+', PREC.UNARY],318      ['-', PREC.UNARY],319      ['!', PREC.UNARY],320      ['~', PREC.UNARY],321    ].map(([operator, precedence]) =>322      prec.left(precedence, seq(323        field('operator', operator),324        field('operand', $.expression)325      ))326    )),327 328    update_expression: $ => prec.left(PREC.UNARY, choice(329      // Post (in|de)crement is evaluated before pre (in|de)crement330      seq($.expression, '++'),331      seq($.expression, '--'),332      seq('++', $.expression),333      seq('--', $.expression)334    )),335 336    primary_expression: $ => choice(337      $._literal,338      $.class_literal,339      $.this,340      $.identifier,341      $._reserved_identifier,342      $.parenthesized_expression,343      $.object_creation_expression,344      $.field_access,345      $.array_access,346      $.method_invocation,347      $.method_reference,348      $.array_creation_expression,349      $.template_expression350    ),351 352    array_creation_expression: $ => prec.right(seq(353      'new',354      repeat($._annotation),355      field('type', $._simple_type),356      choice(357        seq(358          field('dimensions', repeat1($.dimensions_expr)),359          field('dimensions', optional($.dimensions))360        ),361        seq(362          field('dimensions', $.dimensions),363          field('value', $.array_initializer)364        )365      )366    )),367 368    dimensions_expr: $ => seq(repeat($._annotation), '[', $.expression, ']'),369 370    parenthesized_expression: $ => seq('(', $.expression, ')'),371 372    condition: $ => seq('(', $.expression, ')'),373 374    class_literal: $ => prec.dynamic(PREC.CLASS_LITERAL, seq($._unannotated_type, '.', 'class')),375 376    object_creation_expression: $ => choice(377      $._unqualified_object_creation_expression,378      seq($.primary_expression, '.', $._unqualified_object_creation_expression)379    ),380 381    _unqualified_object_creation_expression: $ => prec.right(seq(382      'new',383      choice(384        seq(385          repeat($._annotation),386          field('type_arguments', $.type_arguments),387          repeat($._annotation),388        ),389        repeat($._annotation),390      ),391      field('type', $._simple_type),392      field('arguments', $.argument_list),393      optional($.class_body)394    )),395 396    field_access: $ => seq(397      field('object', choice($.primary_expression, $.super)),398      optional(seq(399        '.',400        $.super401      )),402      '.',403      field('field', choice($.identifier, $._reserved_identifier, $.this))404    ),405 406    template_expression: $ => seq(407      field('template_processor', $.primary_expression),408      '.',409      field('template_argument', $.string_literal)410    ),411 412    array_access: $ => seq(413      field('array', $.primary_expression),414      '[',415      field('index', $.expression),416      ']',417    ),418 419    method_invocation: $ => seq(420      choice(421        field('name', choice($.identifier, $._reserved_identifier)),422        seq(423          field('object', choice($.primary_expression, $.super)),424          '.',425          optional(seq(426            $.super,427            '.'428          )),429          field('type_arguments', optional($.type_arguments)),430          field('name', choice($.identifier, $._reserved_identifier)),431        )432      ),433      field('arguments', $.argument_list)434    ),435 436    argument_list: $ => seq('(', commaSep($.expression), ')'),437 438    method_reference: $ => seq(439      choice($._type, $.primary_expression, $.super),440      '::',441      optional($.type_arguments),442      choice('new', $.identifier)443    ),444 445    type_arguments: $ => seq(446      '<',447      commaSep(choice($._type, $.wildcard)),448      '>'449    ),450 451    wildcard: $ => seq(452      repeat($._annotation),453      '?',454      optional($._wildcard_bounds)455    ),456 457    _wildcard_bounds: $ => choice(458      seq('extends', $._type),459      seq($.super, $._type)460    ),461 462    dimensions: $ => prec.right(repeat1(463      seq(repeat($._annotation), '[', ']')464    )),465 466    switch_expression: $ => seq(467      'switch',468      field('condition', $.parenthesized_expression),469      field('body', $.switch_block)470    ),471 472    switch_block: $ => seq(473      '{',474      choice(475        repeat($.switch_block_statement_group),476        repeat($.switch_rule)477      ),478      '}'479    ),480 481    switch_block_statement_group: $ => prec.left(seq(482      repeat1(seq($.switch_label, ':')),483      repeat($.statement),484    )),485 486    switch_rule: $ => seq(487      $.switch_label,488      '->',489      choice($.expression_statement, $.throw_statement, $.block)490    ),491 492    switch_label: $ => choice(493      seq('case',494        choice(495          $.pattern,496          commaSep1($.expression)497        ),498        optional($.guard)499      ),500      'default'501    ),502 503    pattern: $ => choice(504      $.type_pattern,505      $.record_pattern,506    ),507    type_pattern: $ => seq($._unannotated_type, choice($.identifier, $._reserved_identifier)),508    record_pattern: $ => seq(choice($.identifier, $._reserved_identifier, $.generic_type), $.record_pattern_body),509    record_pattern_body: $ => seq('(', commaSep(choice($.record_pattern_component, $.record_pattern)), ')'),510    record_pattern_component: $ => choice(511      $.underscore_pattern,512      seq(513        $._unannotated_type,514        choice($.identifier, $._reserved_identifier)515    )),516 517    underscore_pattern: $ => '_',518 519    guard: $ => seq('when', $.expression),520 521    // Statements522 523    statement: $ => choice(524      $.declaration,525      $.expression_statement,526      $.labeled_statement,527      $.if_statement,528      $.while_statement,529      $.for_statement,530      $.enhanced_for_statement,531      $.block,532      ';',533      $.assert_statement,534      $.do_statement,535      $.break_statement,536      $.continue_statement,537      $.return_statement,538      $.yield_statement,539      $.switch_expression, // switch statements and expressions are identical540      $.synchronized_statement,541      $.local_variable_declaration,542      $.throw_statement,543      $.try_statement,544      $.try_with_resources_statement545    ),546 547    block: $ => seq(548      '{', repeat($.statement), '}'549    ),550 551    expression_statement: $ => seq(552      $.expression,553      ';'554    ),555 556    labeled_statement: $ => seq(557      $.identifier, ':', $.statement558    ),559 560    assert_statement: $ => choice(561      seq('assert', $.expression, ';'),562      seq('assert', $.expression, ':', $.expression, ';')563    ),564 565    do_statement: $ => seq(566      'do',567      field('body', $.statement),568      'while',569      field('condition', $.parenthesized_expression),570      ';'571    ),572 573    break_statement: $ => seq('break', optional($.identifier), ';'),574 575    continue_statement: $ => seq('continue', optional($.identifier), ';'),576 577    return_statement: $ => seq(578      'return',579      optional($.expression),580      ';'581    ),582 583    yield_statement: $ => seq(584      'yield',585      $.expression,586      ';'587    ),588 589    synchronized_statement: $ => seq(590      'synchronized',591      $.parenthesized_expression,592      field('body', $.block)593    ),594 595    throw_statement: $ => seq('throw', $.expression, ';'),596 597    try_statement: $ => seq(598      'try',599      field('body', $.block),600      choice(601        repeat1($.catch_clause),602        seq(repeat($.catch_clause), $.finally_clause)603      )604    ),605 606    catch_clause: $ => seq(607      'catch',608      '(',609      $.catch_formal_parameter,610      ')',611      field('body', $.block)612    ),613 614    catch_formal_parameter: $ => seq(615      optional($.modifiers),616      $.catch_type,617      $._variable_declarator_id618    ),619 620    catch_type: $ => sep1($._unannotated_type, '|'),621 622    finally_clause: $ => seq('finally', $.block),623 624    try_with_resources_statement: $ => seq(625      'try',626      field('resources', $.resource_specification),627      field('body', $.block),628      repeat($.catch_clause),629      optional($.finally_clause)630    ),631 632    resource_specification: $ => seq(633      '(', sep1($.resource, ';'), optional(';'), ')'634    ),635 636    resource: $ => choice(637      seq(638        optional($.modifiers),639        field('type', $._unannotated_type),640        $._variable_declarator_id,641        '=',642        field('value', $.expression)643      ),644      $.identifier,645      $.field_access646    ),647 648    if_statement: $ => prec.right(seq(649      'if',650      field('condition', $.condition),651      field('consequence', $.statement),652      optional(seq('else', field('alternative', $.statement)))653    )),654 655    while_statement: $ => seq(656      'while',657      field('condition', $.condition),658      field('body', $.statement)659    ),660 661    for_statement: $ => seq(662      'for', '(',663      choice(664        field('init', $.local_variable_declaration),665        seq(666          commaSep(field('init', $.expression)),667          ';'668        )669      ),670      field('condition', optional($.expression)), ';',671      commaSep(field('update', $.expression)), ')',672      field('body', $.statement)673    ),674 675    enhanced_for_statement: $ => seq(676      'for',677      '(',678      optional($.modifiers),679      field('type', $._unannotated_type),680      $._variable_declarator_id,681      ':',682      field('value', $.expression),683      ')',684      field('body', $.statement)685    ),686 687    // Annotations688 689    _annotation: $ => choice(690      $.marker_annotation,691      $.annotation692    ),693 694    marker_annotation: $ => seq(695      '@',696      field('name', $._name)697    ),698 699    annotation: $ => seq(700      '@',701      field('name', $._name),702      field('arguments', $.annotation_argument_list)703    ),704 705    annotation_argument_list: $ => seq(706      '(',707      choice(708        $._element_value,709        commaSep($.element_value_pair),710      ),711      ')'712    ),713 714    element_value_pair: $ => seq(715      field('key', $.identifier),716      '=',717      field('value', $._element_value)718    ),719 720    _element_value: $ => prec(PREC.ELEMENT_VAL, choice(721      $.expression,722      $.element_value_array_initializer,723      $._annotation724    )),725 726    element_value_array_initializer: $ => seq(727      '{',728      commaSep($._element_value),729      optional(','),730      '}'731    ),732 733    // Declarations734 735    declaration: $ => prec(PREC.DECL, choice(736      $.module_declaration,737      $.package_declaration,738      $.import_declaration,739      $.class_declaration,740      $.record_declaration,741      $.interface_declaration,742      $.annotation_type_declaration,743      $.enum_declaration,744    )),745 746    module_declaration: $ => seq(747      repeat($._annotation),748      optional('open'),749      'module',750      field('name', $._name),751      field('body', $.module_body)752    ),753 754    module_body: $ => seq(755      '{',756      repeat($.module_directive),757      '}'758    ),759 760    module_directive: $ => choice(761      $.requires_module_directive,762      $.exports_module_directive,763      $.opens_module_directive,764      $.uses_module_directive,765      $.provides_module_directive766    ),767 768    requires_module_directive: $ => seq(769      'requires',770      repeat(field('modifiers', $.requires_modifier)),771      field('module', $._name),772      ';'773    ),774 775    requires_modifier: $ => choice(776      'transitive',777      'static'778    ),779 780    exports_module_directive: $ => seq(781      'exports',782      field('package', $._name),783      optional(seq(784        'to',785        field('modules', $._name),786        repeat(seq(',', field('modules', $._name)))787      )),788      ';'789    ),790 791    opens_module_directive: $ => seq(792      'opens',793      field('package', $._name),794      optional(seq(795        'to',796        field('modules', $._name),797        repeat(seq(',', field('modules', $._name)))798      )),799      ';'800    ),801 802    uses_module_directive: $ => seq(803      'uses',804      field('type', $._name),805      ';'806    ),807 808    provides_module_directive: $ => seq(809      'provides',810      field('provided', $._name),811      'with',812      $._name,813      repeat(seq(',', (field('provider', $._name)))),814      ';'815    ),816 817    package_declaration: $ => seq(818      repeat($._annotation),819      'package',820      $._name,821      ';'822    ),823 824    import_declaration: $ => seq(825      'import',826      optional('static'),827      $._name,828      optional(seq('.', $.asterisk)),829      ';'830    ),831 832    asterisk: $ => '*',833 834    enum_declaration: $ => seq(835      optional($.modifiers),836      'enum',837      field('name', $.identifier),838      field('interfaces', optional($.super_interfaces)),839      field('body', $.enum_body)840    ),841 842    enum_body: $ => seq(843      '{',844      commaSep($.enum_constant),845      optional(','),846      optional($.enum_body_declarations),847      '}'848    ),849 850    enum_body_declarations: $ => seq(851      ';',852      repeat($._class_body_declaration)853    ),854 855    enum_constant: $ => (seq(856      optional($.modifiers),857      field('name', $.identifier),858      field('arguments', optional($.argument_list)),859      field('body', optional($.class_body))860    )),861 862    class_declaration: $ => seq(863      optional($.modifiers),864      'class',865      field('name', $.identifier),866      optional(field('type_parameters', $.type_parameters)),867      optional(field('superclass', $.superclass)),868      optional(field('interfaces', $.super_interfaces)),869      optional(field('permits', $.permits)),870      field('body', $.class_body)871    ),872 873    modifiers: $ => repeat1(choice(874      $._annotation,875      'public',876      'protected',877      'private',878      'abstract',879      'static',880      'final',881      'strictfp',882      'default',883      'synchronized',884      'native',885      'transient',886      'volatile',887      'sealed',888      'non-sealed',889    )),890 891    type_parameters: $ => seq(892      '<', commaSep1($.type_parameter), '>'893    ),894 895    type_parameter: $ => seq(896      repeat($._annotation),897      alias($.identifier, $.type_identifier),898      optional($.type_bound)899    ),900 901    type_bound: $ => seq('extends', $._type, repeat(seq('&', $._type))),902 903    superclass: $ => seq(904      'extends',905      $._type906    ),907 908    super_interfaces: $ => seq(909      'implements',910      $.type_list911    ),912 913    type_list: $ => seq(914      $._type,915      repeat(seq(',', $._type))916    ),917 918    permits: $ => seq(919      'permits',920      $.type_list921    ),922 923    class_body: $ => seq(924      '{',925      repeat($._class_body_declaration),926      '}'927    ),928 929    _class_body_declaration: $ => choice(930      $.field_declaration,931      $.record_declaration,932      $.method_declaration,933      $.compact_constructor_declaration, // For records.934      $.class_declaration,935      $.interface_declaration,936      $.annotation_type_declaration,937      $.enum_declaration,938      $.block,939      $.static_initializer,940      $.constructor_declaration,941      ';'942    ),943 944    static_initializer: $ => seq(945      'static',946      $.block947    ),948 949    constructor_declaration: $ => seq(950      optional($.modifiers),951      $._constructor_declarator,952      optional($.throws),953      field('body', $.constructor_body)954    ),955 956    _constructor_declarator: $ => seq(957      field('type_parameters', optional($.type_parameters)),958      field('name', $.identifier),959      field('parameters', $.formal_parameters)960    ),961 962    constructor_body: $ => seq(963      '{',964      optional($.explicit_constructor_invocation),965      repeat($.statement),966      '}'967    ),968 969    explicit_constructor_invocation: $ => seq(970      choice(971        seq(972          field('type_arguments', optional($.type_arguments)),973          field('constructor', choice($.this, $.super)),974        ),975        seq(976          field('object', choice($.primary_expression)),977          '.',978          field('type_arguments', optional($.type_arguments)),979          field('constructor', $.super),980        )981      ),982      field('arguments', $.argument_list),983      ';'984    ),985 986    _name: $ => choice(987      $.identifier,988      $._reserved_identifier,989      $.scoped_identifier990    ),991 992    scoped_identifier: $ => seq(993      field('scope', $._name),994      '.',995      field('name', $.identifier)996    ),997 998    field_declaration: $ => seq(999      optional($.modifiers),1000      field('type', $._unannotated_type),1001      $._variable_declarator_list,1002      ';'1003    ),1004 1005    record_declaration: $ => seq(1006      optional($.modifiers),1007      'record',1008      field('name', $.identifier),1009      optional(field('type_parameters', $.type_parameters)),1010      field('parameters', $.formal_parameters),1011      optional(field('interfaces', $.super_interfaces)),1012      field('body', $.class_body)1013    ),1014 1015    annotation_type_declaration: $ => seq(1016      optional($.modifiers),1017      '@interface',1018      field('name', $.identifier),1019      field('body', $.annotation_type_body)1020    ),1021 1022    annotation_type_body: $ => seq(1023      '{',1024      repeat(choice(1025        $.annotation_type_element_declaration,1026        $.constant_declaration,1027        $.class_declaration,1028        $.interface_declaration,1029        $.enum_declaration,1030        $.annotation_type_declaration,1031        ';',1032      )),1033      '}'1034    ),1035 1036    annotation_type_element_declaration: $ => seq(1037      optional($.modifiers),1038      field('type', $._unannotated_type),1039      field('name', choice($.identifier, $._reserved_identifier)),1040      '(', ')',1041      field('dimensions', optional($.dimensions)),1042      optional($._default_value),1043      ';'1044    ),1045 1046    _default_value: $ => seq(1047      'default',1048      field('value', $._element_value)1049    ),1050 1051    interface_declaration: $ => seq(1052      optional($.modifiers),1053      'interface',1054      field('name', $.identifier),1055      field('type_parameters', optional($.type_parameters)),1056      optional($.extends_interfaces),1057      optional(field('permits', $.permits)),1058      field('body', $.interface_body)1059    ),1060 1061    extends_interfaces: $ => seq(1062      'extends',1063      $.type_list1064    ),1065 1066    interface_body: $ => seq(1067      '{',1068      repeat(choice(1069        $.constant_declaration,1070        $.enum_declaration,1071        $.method_declaration,1072        $.class_declaration,1073        $.interface_declaration,1074        $.record_declaration,1075        $.annotation_type_declaration,1076        ';'1077      )),1078      '}'1079    ),1080 1081    constant_declaration: $ => seq(1082      optional($.modifiers),1083      field('type', $._unannotated_type),1084      $._variable_declarator_list,1085      ';'1086    ),1087 1088    _variable_declarator_list: $ => commaSep1(1089      field('declarator', $.variable_declarator)1090    ),1091 1092    variable_declarator: $ => seq(1093      $._variable_declarator_id,1094      optional(seq('=', field('value', $._variable_initializer)))1095    ),1096 1097    _variable_declarator_id: $ => seq(1098      field('name', choice($.identifier, $._reserved_identifier, $.underscore_pattern)),1099      field('dimensions', optional($.dimensions))1100    ),1101 1102    _variable_initializer: $ => choice(1103      $.expression,1104      $.array_initializer1105    ),1106 1107    array_initializer: $ => seq(1108      '{',1109      commaSep($._variable_initializer),1110      optional(','),1111      '}'1112    ),1113 1114    // Types1115 1116    _type: $ => choice(1117      $._unannotated_type,1118      $.annotated_type1119    ),1120 1121    _unannotated_type: $ => choice(1122      $._simple_type,1123      $.array_type1124    ),1125 1126    _simple_type: $ => choice(1127      $.void_type,1128      $.integral_type,1129      $.floating_point_type,1130      $.boolean_type,1131      alias($.identifier, $.type_identifier),1132      $.scoped_type_identifier,1133      $.generic_type1134    ),1135 1136    annotated_type: $ => seq(1137      repeat1($._annotation),1138      $._unannotated_type1139    ),1140 1141    scoped_type_identifier: $ => seq(1142      choice(1143        alias($.identifier, $.type_identifier),1144        $.scoped_type_identifier,1145        $.generic_type1146      ),1147      '.',1148      repeat($._annotation),1149      alias($.identifier, $.type_identifier)1150    ),1151 1152    generic_type: $ => prec.dynamic(PREC.GENERIC, seq(1153      choice(1154        alias($.identifier, $.type_identifier),1155        $.scoped_type_identifier1156      ),1157      $.type_arguments1158    )),1159 1160    array_type: $ => seq(1161      field('element', $._unannotated_type),1162      field('dimensions', $.dimensions)1163    ),1164 1165    integral_type: $ => choice(1166      'byte',1167      'short',1168      'int',1169      'long',1170      'char'1171    ),1172 1173    floating_point_type: $ => choice(1174      'float',1175      'double'1176    ),1177 1178    boolean_type: $ => 'boolean',1179 1180    void_type: $ => 'void',1181 1182    _method_header: $ => seq(1183      optional(seq(1184        field('type_parameters', $.type_parameters),1185        repeat($._annotation)1186      )),1187      field('type', $._unannotated_type),1188      $._method_declarator,1189      optional($.throws)1190    ),1191 1192    _method_declarator: $ => seq(1193      field('name', choice($.identifier, $._reserved_identifier)),1194      field('parameters', $.formal_parameters),1195      field('dimensions', optional($.dimensions))1196    ),1197 1198    formal_parameters: $ => seq(1199      '(',1200      choice(

Showing the first 1,200 of 1301 lines. Download the file for the rest.