Merge commit '3c24aa9365985830421a3a7b6791b415961ea770'

pull/502/head
Wilfred Hughes 2023-03-16 22:36:54 +07:00
commit f76dfdc4f0
15 changed files with 51690 additions and 38368 deletions

@ -8,7 +8,8 @@ Added support for Ada.
Improved parsing for TOML. Improved parsing for TOML.
Updated grammars for Bash, C, C++, C#, Clojure, CMake and Elixir. Updated grammars for Bash, C, C++, C#, Clojure, CMake, Elixir and
Java.
Difftastic now prefers treating files as 'mostly UTF-8' or binary rather than Difftastic now prefers treating files as 'mostly UTF-8' or binary rather than
UTF-16. Many files can be decoded as UTF-16 without decoding errors UTF-16. Many files can be decoded as UTF-16 without decoding errors

@ -0,0 +1,33 @@
name: Publish on crates.io
on:
push:
tags:
- v*
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
run: |
rustup toolchain install stable --profile minimal --no-self-update
- name: Verify publish crate
uses: katyo/publish-crates@v1
with:
dry-run: true
- name: Publish crate
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

@ -1,6 +1,7 @@
tree-sitter-java tree-sitter-java
================ ================
[![Build/test](https://github.com/tree-sitter/tree-sitter-java/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-java/actions/workflows/ci.yml) [![CI](https://github.com/tree-sitter/tree-sitter-java/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-java/actions/workflows/ci.yml)
[![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm)
Java grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). Java grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).

@ -4,7 +4,6 @@ const PREC = {
// https://introcs.cs.princeton.edu/java/11precedence/ // https://introcs.cs.princeton.edu/java/11precedence/
COMMENT: 0, // // /* */ COMMENT: 0, // // /* */
ASSIGN: 1, // = += -= *= /= %= &= ^= |= <<= >>= >>>= ASSIGN: 1, // = += -= *= /= %= &= ^= |= <<= >>= >>>=
SWITCH_EXP: 1, // always prefer to parse switch as expression over statement
DECL: 2, DECL: 2,
ELEMENT_VAL: 2, ELEMENT_VAL: 2,
TERNARY: 3, // ?: TERNARY: 3, // ?:
@ -25,6 +24,7 @@ const PREC = {
ARRAY: 16, // [Index] ARRAY: 16, // [Index]
OBJ_ACCESS: 16, // . OBJ_ACCESS: 16, // .
PARENS: 16, // (Expression) PARENS: 16, // (Expression)
CLASS_LITERAL: 17, // .
}; };
module.exports = grammar({ module.exports = grammar({
@ -66,8 +66,11 @@ module.exports = grammar({
[$._unannotated_type, $.scoped_type_identifier], [$._unannotated_type, $.scoped_type_identifier],
[$._unannotated_type, $.generic_type], [$._unannotated_type, $.generic_type],
[$.generic_type, $.primary_expression], [$.generic_type, $.primary_expression],
[$.expression, $.statement],
// Only conflicts in switch expressions // Only conflicts in switch expressions
[$.lambda_expression, $.primary_expression], [$.lambda_expression, $.primary_expression],
[$.inferred_parameters, $.primary_expression],
[$.class_literal, $.field_access],
], ],
word: $ => $.identifier, word: $ => $.identifier,
@ -88,7 +91,6 @@ module.exports = grammar({
$.false, $.false,
$.character_literal, $.character_literal,
$.string_literal, $.string_literal,
$.text_block,
$.null_literal $.null_literal
), ),
@ -141,24 +143,58 @@ module.exports = grammar({
false: $ => 'false', false: $ => 'false',
character_literal: $ => token(seq( character_literal: $ => token(seq(
"'", '\'',
repeat1(choice( repeat1(choice(
/[^\\'\n]/, /[^\\'\n]/,
/\\./, /\\./,
/\\\n/ /\\\n/
)), )),
"'" '\''
)), )),
string_literal: $ => token(choice( string_literal: $ => choice($._string_literal, $._multiline_string_literal),
seq('"', repeat(choice(/[^\\"\n]/, /\\(.|\n)/)), '"'), _string_literal: $ => seq(
// TODO: support multiline string literals by debugging the following: '"',
// seq('"', repeat(choice(/[^\\"\n]/, /\\(.|\n)/)), '"', '+', /\n/, '"', repeat(choice(/[^\\"\n]/, /\\(.|\n)/))) repeat(choice(
)), $.string_fragment,
$.escape_sequence,
)),
'"'
),
_multiline_string_literal: $ => seq(
'"""',
repeat(choice(
alias($._multiline_string_fragment, $.multiline_string_fragment),
$._escape_sequence,
)),
'"""'
),
// Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
// We give names to the token() constructs containing a regexp
// so as to obtain a node in the CST.
//
string_fragment: $ =>
token.immediate(prec(1, /[^"\\]+/)),
_multiline_string_fragment: () =>
prec.right(choice(
/[^"]+/,
seq(/"[^"]*/, repeat(/[^"]+/))
)),
text_block: $ => token(choice( _escape_sequence: $ =>
seq('"""', /\s*\n/, optional(repeat(choice(/[^\\"]/, /\\(.)/))), '"""'), choice(
)), prec(2, token.immediate(seq('\\', /[^abfnrtvxu'\"\\\?]/))),
prec(1, $.escape_sequence)
),
escape_sequence: () => token.immediate(seq(
'\\',
choice(
/[^xu0-7]/,
/[0-7]{1,3}/,
/x[0-9a-fA-F]{2}/,
/u[0-9a-fA-F]{4}/,
/u{[0-9a-fA-F]+}/
))),
null_literal: $ => 'null', null_literal: $ => 'null',
@ -174,7 +210,7 @@ module.exports = grammar({
$.primary_expression, $.primary_expression,
$.unary_expression, $.unary_expression,
$.cast_expression, $.cast_expression,
prec(PREC.SWITCH_EXP, $.switch_expression), $.switch_expression,
), ),
cast_expression: $ => prec(PREC.CAST, seq( cast_expression: $ => prec(PREC.CAST, seq(
@ -227,12 +263,14 @@ module.exports = grammar({
instanceof_expression: $ => prec(PREC.REL, seq( instanceof_expression: $ => prec(PREC.REL, seq(
field('left', $.expression), field('left', $.expression),
'instanceof', 'instanceof',
field('right', $._type) optional('final'),
field('right', $._type),
field('name', optional(choice($.identifier, $._reserved_identifier)))
)), )),
lambda_expression: $ => seq( lambda_expression: $ => seq(
field('parameters', choice( field('parameters', choice(
$.identifier, $.formal_parameters, $.inferred_parameters $.identifier, $.formal_parameters, $.inferred_parameters, $._reserved_identifier
)), )),
'->', '->',
field('body', choice($.expression, $.block)) field('body', choice($.expression, $.block))
@ -240,7 +278,7 @@ module.exports = grammar({
inferred_parameters: $ => seq( inferred_parameters: $ => seq(
'(', '(',
commaSep1($.identifier), commaSep1(choice($.identifier, $._reserved_identifier)),
')' ')'
), ),
@ -289,6 +327,7 @@ module.exports = grammar({
array_creation_expression: $ => prec.right(seq( array_creation_expression: $ => prec.right(seq(
'new', 'new',
repeat($._annotation),
field('type', $._simple_type), field('type', $._simple_type),
choice( choice(
seq( seq(
@ -306,7 +345,7 @@ module.exports = grammar({
parenthesized_expression: $ => seq('(', $.expression, ')'), parenthesized_expression: $ => seq('(', $.expression, ')'),
class_literal: $ => seq($._unannotated_type, '.', 'class'), class_literal: $ => prec.dynamic(PREC.CLASS_LITERAL, seq($._unannotated_type, '.', 'class')),
object_creation_expression: $ => choice( object_creation_expression: $ => choice(
$._unqualified_object_creation_expression, $._unqualified_object_creation_expression,
@ -434,7 +473,7 @@ module.exports = grammar({
$.continue_statement, $.continue_statement,
$.return_statement, $.return_statement,
$.yield_statement, $.yield_statement,
$.switch_expression, //switch statements and expressions are identical $.switch_expression, // switch statements and expressions are identical
$.synchronized_statement, $.synchronized_statement,
$.local_variable_declaration, $.local_variable_declaration,
$.throw_statement, $.throw_statement,
@ -635,6 +674,7 @@ module.exports = grammar({
$.package_declaration, $.package_declaration,
$.import_declaration, $.import_declaration,
$.class_declaration, $.class_declaration,
$.record_declaration,
$.interface_declaration, $.interface_declaration,
$.annotation_type_declaration, $.annotation_type_declaration,
$.enum_declaration, $.enum_declaration,
@ -827,6 +867,7 @@ module.exports = grammar({
$.field_declaration, $.field_declaration,
$.record_declaration, $.record_declaration,
$.method_declaration, $.method_declaration,
$.compact_constructor_declaration, // For records.
$.class_declaration, $.class_declaration,
$.interface_declaration, $.interface_declaration,
$.annotation_type_declaration, $.annotation_type_declaration,
@ -902,7 +943,9 @@ module.exports = grammar({
optional($.modifiers), optional($.modifiers),
'record', 'record',
field('name', $.identifier), field('name', $.identifier),
optional(field('type_parameters', $.type_parameters)),
field('parameters', $.formal_parameters), field('parameters', $.formal_parameters),
optional(field('interfaces', $.super_interfaces)),
field('body', $.class_body) field('body', $.class_body)
), ),
@ -919,6 +962,7 @@ module.exports = grammar({
$.constant_declaration, $.constant_declaration,
$.class_declaration, $.class_declaration,
$.interface_declaration, $.interface_declaration,
$.enum_declaration,
$.annotation_type_declaration $.annotation_type_declaration
)), )),
'}' '}'
@ -962,6 +1006,7 @@ module.exports = grammar({
$.method_declaration, $.method_declaration,
$.class_declaration, $.class_declaration,
$.interface_declaration, $.interface_declaration,
$.record_declaration,
$.annotation_type_declaration, $.annotation_type_declaration,
';' ';'
)), )),
@ -1129,9 +1174,16 @@ module.exports = grammar({
choice(field('body', $.block), ';') choice(field('body', $.block), ';')
), ),
compact_constructor_declaration: $ => seq(
optional($.modifiers),
field('name', $.identifier),
field('body', $.block)
),
_reserved_identifier: $ => alias(choice( _reserved_identifier: $ => alias(choice(
'open', 'open',
'module' 'module',
'record'
), $.identifier), ), $.identifier),
this: $ => 'this', this: $ => 'this',

@ -73,6 +73,7 @@
(character_literal) (character_literal)
(string_literal) (string_literal)
] @string ] @string
(escape_sequence) @string.escape
[ [
(true) (true)

@ -0,0 +1,3 @@
examples/flink/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/src/main/java/DataStreamJob.java
examples/flink/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/src/main/java/FraudDetectionJob.java
examples/flink/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/src/main/java/FraudDetector.java

@ -26,8 +26,11 @@ function clone_repo {
} }
clone_repo elastic elasticsearch 4d62640bf116af7e825d89c7319a39c3f2f325b4 clone_repo elastic elasticsearch 4d62640bf116af7e825d89c7319a39c3f2f325b4
clone_repo google guava e24fddc5fff7fd36d33ea38737b6606a7e476845 clone_repo google guava v31.1
clone_repo ReactiveX RxJava 8a6bf14fc9a61f7c1c0016ca217be02ca86211d2 clone_repo ReactiveX RxJava v3.1.6
clone_repo apache flink release-1.16.0
clone_repo apache logging-log4j2 rel/2.19.0
clone_repo apache cassandra cassandra-4.1.0
known_failures="$(cat script/known-failures.txt)" known_failures="$(cat script/known-failures.txt)"

@ -52,10 +52,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "string_literal" "name": "string_literal"
}, },
{
"type": "SYMBOL",
"name": "text_block"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "null_literal" "name": "null_literal"
@ -1065,85 +1061,185 @@
} }
}, },
"string_literal": { "string_literal": {
"type": "TOKEN", "type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "SYMBOL",
"name": "_multiline_string_literal"
}
]
},
"_string_literal": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_fragment"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"_multiline_string_literal": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\"\"\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_multiline_string_fragment"
},
"named": true,
"value": "multiline_string_fragment"
},
{
"type": "SYMBOL",
"name": "_escape_sequence"
}
]
}
},
{
"type": "STRING",
"value": "\"\"\""
}
]
},
"string_fragment": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\"\\\\]+"
}
}
},
"_multiline_string_fragment": {
"type": "PREC_RIGHT",
"value": 0,
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "PATTERN",
"value": "[^\"]+"
},
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "PATTERN",
"value": "\"" "value": "\"[^\"]*"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "CHOICE", "type": "PATTERN",
"members": [ "value": "[^\"]+"
{
"type": "PATTERN",
"value": "[^\\\\\"\\n]"
},
{
"type": "PATTERN",
"value": "\\\\(.|\\n)"
}
]
} }
},
{
"type": "STRING",
"value": "\""
} }
] ]
} }
] ]
} }
}, },
"text_block": { "_escape_sequence": {
"type": "TOKEN", "type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 2,
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "PATTERN",
"value": "[^abfnrtvxu'\\\"\\\\\\?]"
}
]
}
}
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "escape_sequence"
}
}
]
},
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": { "content": {
"type": "CHOICE", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SEQ", "type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "PATTERN",
"value": "\"\"\"" "value": "[^xu0-7]"
}, },
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "\\s*\\n" "value": "[0-7]{1,3}"
}, },
{ {
"type": "CHOICE", "type": "PATTERN",
"members": [ "value": "x[0-9a-fA-F]{2}"
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\\\\"]"
},
{
"type": "PATTERN",
"value": "\\\\(.)"
}
]
}
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "STRING", "type": "PATTERN",
"value": "\"\"\"" "value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "u{[0-9a-fA-F]+}"
} }
] ]
} }
@ -1194,12 +1290,8 @@
"name": "cast_expression" "name": "cast_expression"
}, },
{ {
"type": "PREC", "type": "SYMBOL",
"value": 1, "name": "switch_expression"
"content": {
"type": "SYMBOL",
"name": "switch_expression"
}
} }
] ]
}, },
@ -2010,6 +2102,18 @@
"type": "STRING", "type": "STRING",
"value": "instanceof" "value": "instanceof"
}, },
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "final"
},
{
"type": "BLANK"
}
]
},
{ {
"type": "FIELD", "type": "FIELD",
"name": "right", "name": "right",
@ -2017,6 +2121,31 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_type" "name": "_type"
} }
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
},
{
"type": "BLANK"
}
]
}
} }
] ]
} }
@ -2041,6 +2170,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "inferred_parameters" "name": "inferred_parameters"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
} }
] ]
} }
@ -2079,8 +2212,17 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -2092,8 +2234,17 @@
"value": "," "value": ","
}, },
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
} }
] ]
} }
@ -2376,6 +2527,13 @@
"type": "STRING", "type": "STRING",
"value": "new" "value": "new"
}, },
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_annotation"
}
},
{ {
"type": "FIELD", "type": "FIELD",
"name": "type", "name": "type",
@ -2487,21 +2645,25 @@
] ]
}, },
"class_literal": { "class_literal": {
"type": "SEQ", "type": "PREC_DYNAMIC",
"members": [ "value": 17,
{ "content": {
"type": "SYMBOL", "type": "SEQ",
"name": "_unannotated_type" "members": [
}, {
{ "type": "SYMBOL",
"type": "STRING", "name": "_unannotated_type"
"value": "." },
}, {
{ "type": "STRING",
"type": "STRING", "value": "."
"value": "class" },
} {
] "type": "STRING",
"value": "class"
}
]
}
}, },
"object_creation_expression": { "object_creation_expression": {
"type": "CHOICE", "type": "CHOICE",
@ -4366,6 +4528,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "class_declaration" "name": "class_declaration"
}, },
{
"type": "SYMBOL",
"name": "record_declaration"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "interface_declaration" "name": "interface_declaration"
@ -5359,6 +5525,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "method_declaration" "name": "method_declaration"
}, },
{
"type": "SYMBOL",
"name": "compact_constructor_declaration"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "class_declaration" "name": "class_declaration"
@ -5724,6 +5894,22 @@
"name": "identifier" "name": "identifier"
} }
}, },
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "type_parameters",
"content": {
"type": "SYMBOL",
"name": "type_parameters"
}
},
{
"type": "BLANK"
}
]
},
{ {
"type": "FIELD", "type": "FIELD",
"name": "parameters", "name": "parameters",
@ -5732,6 +5918,22 @@
"name": "formal_parameters" "name": "formal_parameters"
} }
}, },
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "interfaces",
"content": {
"type": "SYMBOL",
"name": "super_interfaces"
}
},
{
"type": "BLANK"
}
]
},
{ {
"type": "FIELD", "type": "FIELD",
"name": "body", "name": "body",
@ -5807,6 +6009,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "interface_declaration" "name": "interface_declaration"
}, },
{
"type": "SYMBOL",
"name": "enum_declaration"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "annotation_type_declaration" "name": "annotation_type_declaration"
@ -6036,6 +6242,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "interface_declaration" "name": "interface_declaration"
}, },
{
"type": "SYMBOL",
"name": "record_declaration"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "annotation_type_declaration" "name": "annotation_type_declaration"
@ -6870,6 +7080,39 @@
} }
] ]
}, },
"compact_constructor_declaration": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "modifiers"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "block"
}
}
]
},
"_reserved_identifier": { "_reserved_identifier": {
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {
@ -6882,6 +7125,10 @@
{ {
"type": "STRING", "type": "STRING",
"value": "module" "value": "module"
},
{
"type": "STRING",
"value": "record"
} }
] ]
}, },
@ -7010,9 +7257,21 @@
"generic_type", "generic_type",
"primary_expression" "primary_expression"
], ],
[
"expression",
"statement"
],
[ [
"lambda_expression", "lambda_expression",
"primary_expression" "primary_expression"
],
[
"inferred_parameters",
"primary_expression"
],
[
"class_literal",
"field_access"
] ]
], ],
"precedences": [], "precedences": [],

@ -43,10 +43,6 @@
"type": "string_literal", "type": "string_literal",
"named": true "named": true
}, },
{
"type": "text_block",
"named": true
},
{ {
"type": "true", "type": "true",
"named": true "named": true
@ -160,6 +156,10 @@
{ {
"type": "package_declaration", "type": "package_declaration",
"named": true "named": true
},
{
"type": "record_declaration",
"named": true
} }
] ]
}, },
@ -483,6 +483,10 @@
"type": "constant_declaration", "type": "constant_declaration",
"named": true "named": true
}, },
{
"type": "enum_declaration",
"named": true
},
{ {
"type": "interface_declaration", "type": "interface_declaration",
"named": true "named": true
@ -673,6 +677,20 @@
} }
] ]
} }
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "annotation",
"named": true
},
{
"type": "marker_annotation",
"named": true
}
]
} }
}, },
{ {
@ -1093,6 +1111,10 @@
"type": "class_declaration", "type": "class_declaration",
"named": true "named": true
}, },
{
"type": "compact_constructor_declaration",
"named": true
},
{ {
"type": "constructor_declaration", "type": "constructor_declaration",
"named": true "named": true
@ -1215,6 +1237,42 @@
] ]
} }
}, },
{
"type": "compact_constructor_declaration",
"named": true,
"fields": {
"body": {
"multiple": false,
"required": true,
"types": [
{
"type": "block",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "modifiers",
"named": true
}
]
}
},
{ {
"type": "constant_declaration", "type": "constant_declaration",
"named": true, "named": true,
@ -1583,6 +1641,10 @@
"type": "class_declaration", "type": "class_declaration",
"named": true "named": true
}, },
{
"type": "compact_constructor_declaration",
"named": true
},
{ {
"type": "constructor_declaration", "type": "constructor_declaration",
"named": true "named": true
@ -2150,6 +2212,16 @@
} }
] ]
}, },
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"right": { "right": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@ -2198,6 +2270,10 @@
{ {
"type": "method_declaration", "type": "method_declaration",
"named": true "named": true
},
{
"type": "record_declaration",
"named": true
} }
] ]
} }
@ -2628,6 +2704,11 @@
] ]
} }
}, },
{
"type": "multiline_string_fragment",
"named": true,
"fields": {}
},
{ {
"type": "object_creation_expression", "type": "object_creation_expression",
"named": true, "named": true,
@ -2877,6 +2958,16 @@
} }
] ]
}, },
"interfaces": {
"multiple": false,
"required": false,
"types": [
{
"type": "super_interfaces",
"named": true
}
]
},
"name": { "name": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@ -2896,6 +2987,16 @@
"named": true "named": true
} }
] ]
},
"type_parameters": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_parameters",
"named": true
}
]
} }
}, },
"children": { "children": {
@ -3137,6 +3238,29 @@
] ]
} }
}, },
{
"type": "string_literal",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
},
{
"type": "multiline_string_fragment",
"named": true
},
{
"type": "string_fragment",
"named": true
}
]
}
},
{ {
"type": "super_interfaces", "type": "super_interfaces",
"named": true, "named": true,
@ -3715,6 +3839,14 @@
"type": "!=", "type": "!=",
"named": false "named": false
}, },
{
"type": "\"",
"named": false
},
{
"type": "\"\"\"",
"named": false
},
{ {
"type": "%", "type": "%",
"named": false "named": false
@ -3967,6 +4099,10 @@
"type": "enum", "type": "enum",
"named": false "named": false
}, },
{
"type": "escape_sequence",
"named": true
},
{ {
"type": "exports", "type": "exports",
"named": false "named": false
@ -4124,7 +4260,7 @@
"named": false "named": false
}, },
{ {
"type": "string_literal", "type": "string_fragment",
"named": true "named": true
}, },
{ {
@ -4139,10 +4275,6 @@
"type": "synchronized", "type": "synchronized",
"named": false "named": false
}, },
{
"type": "text_block",
"named": true
},
{ {
"type": "this", "type": "this",
"named": true "named": true

File diff suppressed because it is too large Load Diff

@ -123,6 +123,7 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *); unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned); void (*deserialize)(void *, const char *, unsigned);
} external_scanner; } external_scanner;
const TSStateId *primary_state_ids;
}; };
/* /*

@ -100,9 +100,9 @@ module com.foo { }
(identifier) (identifier)
(annotation_argument_list (annotation_argument_list
(element_value_pair (identifier) (decimal_integer_literal)) (element_value_pair (identifier) (decimal_integer_literal))
(element_value_pair (identifier) (string_literal)) (element_value_pair (identifier) (string_literal (string_fragment)))
(element_value_pair (identifier) (string_literal)) (element_value_pair (identifier) (string_literal (string_fragment)))
(element_value_pair (identifier) (string_literal)))) (element_value_pair (identifier) (string_literal (string_fragment)))))
(scoped_identifier (identifier) (identifier)) (scoped_identifier (identifier) (identifier))
(module_body))) (module_body)))
@ -138,7 +138,7 @@ module com.foo {}
(module_declaration (module_declaration
(annotation (annotation
(identifier) (identifier)
(annotation_argument_list (string_literal))) (annotation_argument_list (string_literal (string_fragment))))
(scoped_identifier (scoped_identifier
(identifier) (identifier)
(identifier)) (identifier))
@ -597,8 +597,76 @@ enum HandSign {
================= =================
record declaration enum declaration inside an interface
=================
public @interface Foo {
enum HandSign {
SCISSOR, PAPER, STONE
}
}
---
(program
(annotation_type_declaration
(modifiers)
name: (identifier)
body: (annotation_type_body
(enum_declaration
name: (identifier)
body: (enum_body
(enum_constant
name: (identifier))
(enum_constant
name: (identifier))
(enum_constant
name: (identifier)))))))
================= =================
record declaration
==================
public record Foo(int bar) {
}
---
(program
(record_declaration
(modifiers)
name: (identifier)
parameters: (formal_parameters
(formal_parameter
type: (integral_type)
name: (identifier)))
body: (class_body)))
================================
record declaration with generics
================================
public record Foo<T>(T bar) {
}
---
(program
(record_declaration
(modifiers)
name: (identifier)
type_parameters: (type_parameters
(type_parameter
(type_identifier)))
parameters: (formal_parameters
(formal_parameter
type: (type_identifier)
name: (identifier)))
body: (class_body)))
=================================
record declaration inside a class
=================================
public class Usecase { public class Usecase {
public static record Commande(@NotNull String param) { public static record Commande(@NotNull String param) {
@ -638,6 +706,81 @@ public class Usecase {
arguments: (argument_list arguments: (argument_list
(string_literal))))))))))) (string_literal)))))))))))
======================================
record declaration inside an interface
======================================
interface I { record R(int a) {} }
---
(program
(interface_declaration
(identifier)
(interface_body
(record_declaration
(identifier)
(formal_parameters
(formal_parameter
(integral_type)
(identifier)))
(class_body)))))
===========================================
record declaration with compact constructor
===========================================
record Person(int age) {
public Person {
if (age < 0) throw new IllegalArgumentException("invalid age");
}
}
---
(program
(record_declaration
(identifier)
(formal_parameters
(formal_parameter
(integral_type)
(identifier)))
(class_body
(compact_constructor_declaration
(modifiers)
(identifier)
(block
(if_statement
(parenthesized_expression
(binary_expression
(identifier)
(decimal_integer_literal)))
(throw_statement
(object_creation_expression
(type_identifier)
(argument_list
(string_literal
(string_fragment)))))))))))
============================================
record declaration that implements interface
============================================
record R() implements I {}
---
(program
(record_declaration
(identifier)
(formal_parameters)
(super_interfaces
(type_list
(type_identifier)))
(class_body)))
============================================== ==============================================
class declaration with dollar-sign identifiers class declaration with dollar-sign identifiers
============================================== ==============================================

@ -65,6 +65,8 @@ instanceof expressions
a instanceof C.D; a instanceof C.D;
a instanceof List<B>; a instanceof List<B>;
c instanceof C[]; c instanceof C[];
c instanceof C foo;
d instanceof final D bar;
--- ---
@ -77,7 +79,16 @@ c instanceof C[];
(generic_type (type_identifier) (type_arguments (type_identifier))))) (generic_type (type_identifier) (type_arguments (type_identifier)))))
(expression_statement (instanceof_expression (expression_statement (instanceof_expression
(identifier) (identifier)
(array_type (type_identifier) (dimensions))))) (array_type (type_identifier) (dimensions))))
(expression_statement (instanceof_expression
(identifier)
(type_identifier)
(identifier)))
(expression_statement (instanceof_expression
(identifier)
(type_identifier)
(identifier))))
=========================================================== ===========================================================
if statements if statements
@ -225,7 +236,7 @@ for (j.init(i); j.check(); j.update()) {
field: (identifier)) field: (identifier))
name: (identifier) name: (identifier)
arguments: (argument_list (binary_expression arguments: (argument_list (binary_expression
left: (string_literal) left: (string_literal (string_fragment))
right: (identifier))))))) right: (identifier)))))))
(for_statement (for_statement
init: (method_invocation init: (method_invocation
@ -316,7 +327,7 @@ class WhileDemo {
field: (identifier)) field: (identifier))
name: (identifier) name: (identifier)
arguments: (argument_list arguments: (argument_list
(binary_expression left: (string_literal) right: (identifier))))) (binary_expression left: (string_literal (string_fragment)) right: (identifier)))))
(expression_statement (update_expression (identifier)))))))))) (expression_statement (update_expression (identifier))))))))))
================================== ==================================
@ -337,7 +348,7 @@ try (FileInputStream input = new FileInputStream("file.txt")) {
name: (identifier) name: (identifier)
value: (object_creation_expression value: (object_creation_expression
type: (type_identifier) type: (type_identifier)
arguments: (argument_list (string_literal))))) arguments: (argument_list (string_literal (string_fragment))))))
body: (block body: (block
(local_variable_declaration (local_variable_declaration
type: (integral_type) type: (integral_type)
@ -385,7 +396,7 @@ class Duck {
(annotation_argument_list (annotation_argument_list
(element_value_pair (element_value_pair
(identifier) (identifier)
(string_literal)))) (string_literal (string_fragment)))))
(annotation (annotation
(identifier) (identifier)
(annotation_argument_list (annotation_argument_list
@ -437,10 +448,32 @@ class Quack {
(class_declaration (class_declaration
(modifiers (modifiers
(annotation (identifier) (annotation_argument_list (field_access (identifier) (identifier)))) (annotation (identifier) (annotation_argument_list (field_access (identifier) (identifier))))
(annotation (identifier) (annotation_argument_list (string_literal)))) (annotation (identifier) (annotation_argument_list (string_literal (string_fragment)))))
(identifier) (identifier)
(class_body))) (class_body)))
==================================
annotation in array creation
==================================
String[] allMyStrings = new @Nullable String[5];
---
(program
(local_variable_declaration
(array_type
(type_identifier)
(dimensions))
(variable_declarator
(identifier)
(array_creation_expression
(marker_annotation
(identifier))
(type_identifier)
(dimensions_expr
(decimal_integer_literal))))))
================================== ==================================
lambda expression lambda expression
================================== ==================================
@ -448,7 +481,7 @@ lambda expression
class LambdaTest { class LambdaTest {
void singleton() { void singleton() {
version -> create; version -> create;
(a, b) -> a + b; (record, b) -> record + b;
} }
} }
@ -529,7 +562,8 @@ public class SwitchDemo {
(expression_statement (expression_statement
(assignment_expression (assignment_expression
left: (identifier) left: (identifier)
right: (string_literal))) right: (string_literal
(string_fragment))))
(break_statement)) (break_statement))
(switch_block_statement_group (switch_block_statement_group
(switch_label (switch_label
@ -537,7 +571,8 @@ public class SwitchDemo {
(expression_statement (expression_statement
(assignment_expression (assignment_expression
left: (identifier) left: (identifier)
right: (string_literal))) right: (string_literal
(string_fragment))))
(break_statement)) (break_statement))
(switch_block_statement_group (switch_block_statement_group
(switch_label (switch_label
@ -545,14 +580,16 @@ public class SwitchDemo {
(expression_statement (expression_statement
(assignment_expression (assignment_expression
left: (identifier) left: (identifier)
right: (string_literal))) right: (string_literal
(string_fragment))))
(break_statement)) (break_statement))
(switch_block_statement_group (switch_block_statement_group
(switch_label) (switch_label)
(expression_statement (expression_statement
(assignment_expression (assignment_expression
left: (identifier) left: (identifier)
right: (string_literal))) right: (string_literal
(string_fragment))))
(break_statement)))) (break_statement))))
(expression_statement (expression_statement
(method_invocation (method_invocation
@ -708,7 +745,8 @@ class Test {
field: (identifier)) field: (identifier))
name: (identifier) name: (identifier)
arguments: (argument_list arguments: (argument_list
(string_literal)))) (string_literal
(string_fragment)))))
(yield_statement (yield_statement
(decimal_integer_literal)))))))))))) (decimal_integer_literal))))))))))))
@ -897,6 +935,58 @@ class Test {
(decimal_integer_literal))))))))))))) (decimal_integer_literal)))))))))))))
================================== ==================================
switch statement and pre-increment
==================================
class Test {
int i;
static void foo(boolean bar) {
int ddsd;
switch(bar) {
default:
i = 3;
}
++ddsd;
}
}
---
(program
(class_declaration
(identifier)
(class_body
(field_declaration
(integral_type)
(variable_declarator
(identifier)))
(method_declaration
(modifiers)
(void_type)
(identifier)
(formal_parameters
(formal_parameter
(boolean_type)
(identifier)))
(block
(local_variable_declaration
(integral_type)
(variable_declarator
(identifier)))
(switch_expression
(parenthesized_expression
(identifier))
(switch_block
(switch_block_statement_group
(switch_label)
(expression_statement
(assignment_expression
(identifier)
(decimal_integer_literal))))))
(expression_statement
(update_expression
(identifier))))))))
==================================
type arguments type arguments
================================== ==================================
@ -1074,3 +1164,53 @@ $cibleVisée2 = 2;
(assignment_expression (assignment_expression
(identifier) (identifier)
(decimal_integer_literal)))) (decimal_integer_literal))))
================================================================================
Local variable declaration with scoped type identifiers
================================================================================
util.List<Integer> x = null;
java.util.List<Integer> x = null;
java.util.List<java.lang.Integer> x = null;
--------------------------------------------------------------------------------
(program
(local_variable_declaration
(generic_type
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_arguments
(type_identifier)))
(variable_declarator
(identifier)
(null_literal)))
(local_variable_declaration
(generic_type
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))
(type_arguments
(type_identifier)))
(variable_declarator
(identifier)
(null_literal)))
(local_variable_declaration
(generic_type
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))
(type_arguments
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))))
(variable_declarator
(identifier)
(null_literal))))

@ -147,10 +147,17 @@ string literals
--- ---
(program (program
(expression_statement (string_literal)) (expression_statement
(expression_statement (string_literal)) (string_literal))
(expression_statement (string_literal)) (expression_statement
(expression_statement (string_literal))) (string_literal
(escape_sequence)))
(expression_statement
(string_literal
(string_fragment)))
(expression_statement
(string_literal
(string_fragment))))
=============== ===============
text block text block
@ -169,13 +176,84 @@ Closing token
at new line at new line
"""; """;
"""
{
"foo": 4
}
""";
"""
"this is single double quotes"
""this is double quotes""
"" """;
"""
"hi
""";
"""
\\
""";
---
(program
(expression_statement
(string_literal
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment)
(multiline_string_fragment)))
(expression_statement
(string_literal
(multiline_string_fragment))))
===============
escape sequences
===============
"\n\a\b\fhi im a piece of text\t\v and im some more text \\\'\"\?";
--- ---
(program (program
(expression_statement (text_block)) (expression_statement
(expression_statement (text_block)) (string_literal
(expression_statement (text_block)) (escape_sequence)
(expression_statement (text_block))) (escape_sequence)
(escape_sequence)
(escape_sequence)
(string_fragment)
(escape_sequence)
(escape_sequence)
(string_fragment)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence))))
============= =============
null literals null literals
@ -307,3 +385,15 @@ ascii escapes
(expression_statement (character_literal)) (expression_statement (character_literal))
(expression_statement (character_literal)) (expression_statement (character_literal))
(expression_statement (character_literal))) (expression_statement (character_literal)))
========================
class literals
========================
String.class;
---
(program
(expression_statement
(class_literal (type_identifier))))