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.
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
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
================
[![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).

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

@ -73,6 +73,7 @@
(character_literal)
(string_literal)
] @string
(escape_sequence) @string.escape
[
(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 google guava e24fddc5fff7fd36d33ea38737b6606a7e476845
clone_repo ReactiveX RxJava 8a6bf14fc9a61f7c1c0016ca217be02ca86211d2
clone_repo google guava v31.1
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)"

@ -52,10 +52,6 @@
"type": "SYMBOL",
"name": "string_literal"
},
{
"type": "SYMBOL",
"name": "text_block"
},
{
"type": "SYMBOL",
"name": "null_literal"
@ -1065,11 +1061,19 @@
}
},
"string_literal": {
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_literal"
},
{
"type": "SYMBOL",
"name": "_multiline_string_literal"
}
]
},
"_string_literal": {
"type": "SEQ",
"members": [
{
@ -1082,12 +1086,12 @@
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\\\\"\\n]"
"type": "SYMBOL",
"name": "string_fragment"
},
{
"type": "PATTERN",
"value": "\\\\(.|\\n)"
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
@ -1097,53 +1101,145 @@
"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": "[^\"\\\\]+"
}
}
},
"text_block": {
"type": "TOKEN",
"_multiline_string_fragment": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\"]+"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\"\"\""
"type": "PATTERN",
"value": "\"[^\"]*"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\s*\\n"
"value": "[^\"]+"
}
}
]
}
]
}
},
{
"_escape_sequence": {
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"type": "PREC",
"value": 2,
"content": {
"type": "CHOICE",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^\\\\\"]"
"type": "STRING",
"value": "\\"
},
{
"type": "PATTERN",
"value": "\\\\(.)"
"value": "[^abfnrtvxu'\\\"\\\\\\?]"
}
]
}
}
},
{
"type": "BLANK"
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "escape_sequence"
}
}
]
},
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\"\"\""
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^xu0-7]"
},
{
"type": "PATTERN",
"value": "[0-7]{1,3}"
},
{
"type": "PATTERN",
"value": "x[0-9a-fA-F]{2}"
},
{
"type": "PATTERN",
"value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "u{[0-9a-fA-F]+}"
}
]
}
@ -1194,13 +1290,9 @@
"name": "cast_expression"
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "switch_expression"
}
}
]
},
"cast_expression": {
@ -2010,6 +2102,18 @@
"type": "STRING",
"value": "instanceof"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "final"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "right",
@ -2017,6 +2121,31 @@
"type": "SYMBOL",
"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",
"name": "inferred_parameters"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
}
@ -2077,11 +2210,20 @@
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
},
{
"type": "REPEAT",
"content": {
@ -2091,9 +2233,18 @@
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
}
]
}
@ -2376,6 +2527,13 @@
"type": "STRING",
"value": "new"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_annotation"
}
},
{
"type": "FIELD",
"name": "type",
@ -2487,6 +2645,9 @@
]
},
"class_literal": {
"type": "PREC_DYNAMIC",
"value": 17,
"content": {
"type": "SEQ",
"members": [
{
@ -2502,6 +2663,7 @@
"value": "class"
}
]
}
},
"object_creation_expression": {
"type": "CHOICE",
@ -4366,6 +4528,10 @@
"type": "SYMBOL",
"name": "class_declaration"
},
{
"type": "SYMBOL",
"name": "record_declaration"
},
{
"type": "SYMBOL",
"name": "interface_declaration"
@ -5359,6 +5525,10 @@
"type": "SYMBOL",
"name": "method_declaration"
},
{
"type": "SYMBOL",
"name": "compact_constructor_declaration"
},
{
"type": "SYMBOL",
"name": "class_declaration"
@ -5724,6 +5894,22 @@
"name": "identifier"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "type_parameters",
"content": {
"type": "SYMBOL",
"name": "type_parameters"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "parameters",
@ -5732,6 +5918,22 @@
"name": "formal_parameters"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "interfaces",
"content": {
"type": "SYMBOL",
"name": "super_interfaces"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
@ -5807,6 +6009,10 @@
"type": "SYMBOL",
"name": "interface_declaration"
},
{
"type": "SYMBOL",
"name": "enum_declaration"
},
{
"type": "SYMBOL",
"name": "annotation_type_declaration"
@ -6036,6 +6242,10 @@
"type": "SYMBOL",
"name": "interface_declaration"
},
{
"type": "SYMBOL",
"name": "record_declaration"
},
{
"type": "SYMBOL",
"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": {
"type": "ALIAS",
"content": {
@ -6882,6 +7125,10 @@
{
"type": "STRING",
"value": "module"
},
{
"type": "STRING",
"value": "record"
}
]
},
@ -7010,9 +7257,21 @@
"generic_type",
"primary_expression"
],
[
"expression",
"statement"
],
[
"lambda_expression",
"primary_expression"
],
[
"inferred_parameters",
"primary_expression"
],
[
"class_literal",
"field_access"
]
],
"precedences": [],

@ -43,10 +43,6 @@
"type": "string_literal",
"named": true
},
{
"type": "text_block",
"named": true
},
{
"type": "true",
"named": true
@ -160,6 +156,10 @@
{
"type": "package_declaration",
"named": true
},
{
"type": "record_declaration",
"named": true
}
]
},
@ -483,6 +483,10 @@
"type": "constant_declaration",
"named": true
},
{
"type": "enum_declaration",
"named": true
},
{
"type": "interface_declaration",
"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",
"named": true
},
{
"type": "compact_constructor_declaration",
"named": true
},
{
"type": "constructor_declaration",
"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",
"named": true,
@ -1583,6 +1641,10 @@
"type": "class_declaration",
"named": true
},
{
"type": "compact_constructor_declaration",
"named": true
},
{
"type": "constructor_declaration",
"named": true
@ -2150,6 +2212,16 @@
}
]
},
"name": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
},
"right": {
"multiple": false,
"required": true,
@ -2198,6 +2270,10 @@
{
"type": "method_declaration",
"named": true
},
{
"type": "record_declaration",
"named": true
}
]
}
@ -2628,6 +2704,11 @@
]
}
},
{
"type": "multiline_string_fragment",
"named": true,
"fields": {}
},
{
"type": "object_creation_expression",
"named": true,
@ -2877,6 +2958,16 @@
}
]
},
"interfaces": {
"multiple": false,
"required": false,
"types": [
{
"type": "super_interfaces",
"named": true
}
]
},
"name": {
"multiple": false,
"required": true,
@ -2896,6 +2987,16 @@
"named": true
}
]
},
"type_parameters": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_parameters",
"named": true
}
]
}
},
"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",
"named": true,
@ -3715,6 +3839,14 @@
"type": "!=",
"named": false
},
{
"type": "\"",
"named": false
},
{
"type": "\"\"\"",
"named": false
},
{
"type": "%",
"named": false
@ -3967,6 +4099,10 @@
"type": "enum",
"named": false
},
{
"type": "escape_sequence",
"named": true
},
{
"type": "exports",
"named": false
@ -4124,7 +4260,7 @@
"named": false
},
{
"type": "string_literal",
"type": "string_fragment",
"named": true
},
{
@ -4139,10 +4275,6 @@
"type": "synchronized",
"named": false
},
{
"type": "text_block",
"named": true
},
{
"type": "this",
"named": true

File diff suppressed because it is too large Load Diff

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

@ -100,9 +100,9 @@ module com.foo { }
(identifier)
(annotation_argument_list
(element_value_pair (identifier) (decimal_integer_literal))
(element_value_pair (identifier) (string_literal))
(element_value_pair (identifier) (string_literal))
(element_value_pair (identifier) (string_literal))))
(element_value_pair (identifier) (string_literal (string_fragment)))
(element_value_pair (identifier) (string_literal (string_fragment)))
(element_value_pair (identifier) (string_literal (string_fragment)))))
(scoped_identifier (identifier) (identifier))
(module_body)))
@ -138,7 +138,7 @@ module com.foo {}
(module_declaration
(annotation
(identifier)
(annotation_argument_list (string_literal)))
(annotation_argument_list (string_literal (string_fragment))))
(scoped_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 static record Commande(@NotNull String param) {
@ -638,6 +706,81 @@ public class Usecase {
arguments: (argument_list
(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
==============================================

@ -65,6 +65,8 @@ instanceof expressions
a instanceof C.D;
a instanceof List<B>;
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)))))
(expression_statement (instanceof_expression
(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
@ -225,7 +236,7 @@ for (j.init(i); j.check(); j.update()) {
field: (identifier))
name: (identifier)
arguments: (argument_list (binary_expression
left: (string_literal)
left: (string_literal (string_fragment))
right: (identifier)))))))
(for_statement
init: (method_invocation
@ -316,7 +327,7 @@ class WhileDemo {
field: (identifier))
name: (identifier)
arguments: (argument_list
(binary_expression left: (string_literal) right: (identifier)))))
(binary_expression left: (string_literal (string_fragment)) right: (identifier)))))
(expression_statement (update_expression (identifier))))))))))
==================================
@ -337,7 +348,7 @@ try (FileInputStream input = new FileInputStream("file.txt")) {
name: (identifier)
value: (object_creation_expression
type: (type_identifier)
arguments: (argument_list (string_literal)))))
arguments: (argument_list (string_literal (string_fragment))))))
body: (block
(local_variable_declaration
type: (integral_type)
@ -385,7 +396,7 @@ class Duck {
(annotation_argument_list
(element_value_pair
(identifier)
(string_literal))))
(string_literal (string_fragment)))))
(annotation
(identifier)
(annotation_argument_list
@ -437,10 +448,32 @@ class Quack {
(class_declaration
(modifiers
(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)
(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
==================================
@ -448,7 +481,7 @@ lambda expression
class LambdaTest {
void singleton() {
version -> create;
(a, b) -> a + b;
(record, b) -> record + b;
}
}
@ -529,7 +562,8 @@ public class SwitchDemo {
(expression_statement
(assignment_expression
left: (identifier)
right: (string_literal)))
right: (string_literal
(string_fragment))))
(break_statement))
(switch_block_statement_group
(switch_label
@ -537,7 +571,8 @@ public class SwitchDemo {
(expression_statement
(assignment_expression
left: (identifier)
right: (string_literal)))
right: (string_literal
(string_fragment))))
(break_statement))
(switch_block_statement_group
(switch_label
@ -545,14 +580,16 @@ public class SwitchDemo {
(expression_statement
(assignment_expression
left: (identifier)
right: (string_literal)))
right: (string_literal
(string_fragment))))
(break_statement))
(switch_block_statement_group
(switch_label)
(expression_statement
(assignment_expression
left: (identifier)
right: (string_literal)))
right: (string_literal
(string_fragment))))
(break_statement))))
(expression_statement
(method_invocation
@ -708,7 +745,8 @@ class Test {
field: (identifier))
name: (identifier)
arguments: (argument_list
(string_literal))))
(string_literal
(string_fragment)))))
(yield_statement
(decimal_integer_literal))))))))))))
@ -897,6 +935,58 @@ class Test {
(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
==================================
@ -1074,3 +1164,53 @@ $cibleVisée2 = 2;
(assignment_expression
(identifier)
(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
(expression_statement (string_literal))
(expression_statement (string_literal))
(expression_statement (string_literal))
(expression_statement (string_literal)))
(expression_statement
(string_literal))
(expression_statement
(string_literal
(escape_sequence)))
(expression_statement
(string_literal
(string_fragment)))
(expression_statement
(string_literal
(string_fragment))))
===============
text block
@ -169,13 +176,84 @@ Closing token
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
(expression_statement (text_block))
(expression_statement (text_block))
(expression_statement (text_block))
(expression_statement (text_block)))
(expression_statement
(string_literal
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(string_fragment)
(escape_sequence)
(escape_sequence)
(string_fragment)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence))))
=============
null literals
@ -307,3 +385,15 @@ ascii escapes
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal)))
========================
class literals
========================
String.class;
---
(program
(expression_statement
(class_literal (type_identifier))))