Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-sitter-java

Package Overview
Dependencies
Maintainers
9
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter-java - npm Package Compare versions

Comparing version 0.13.0 to 0.15.0

src/node-types.json

10

corpus/comments.txt

@@ -13,9 +13,13 @@ ====

===
======================
comments and literals
===
======================
123;
// comment
---
(program (integer_literal (decimal_integer_literal)) (comment))
(program
(expression_statement (decimal_integer_literal))
(comment))

@@ -1,7 +0,7 @@

===
===============
local variable
===
===============
class A {
int b() {
public int b() {
int c = 5;

@@ -15,24 +15,53 @@ }

(class_declaration
(identifier)
(class_body
name: (identifier)
body: (class_body
(method_declaration
(method_header
(integral_type)
(method_declarator
(identifier)))
(method_body
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))
(integer_literal
(decimal_integer_literal))))))))))))
(modifiers)
type: (integral_type)
name: (identifier)
parameters: (formal_parameters)
body: (block
(local_variable_declaration_statement
(local_variable_declaration
type: (integral_type)
declarator: (variable_declarator
name: (identifier)
value: (decimal_integer_literal)))))))))
===
=====================
local array variable
=====================
String[] nodeNames = internalCluster().getNodeNames();
Integer[][] inputArrays = new Integer[0x100][];
---
(program
(local_variable_declaration_statement (local_variable_declaration
type: (array_type
element: (type_identifier)
dimensions: (dimensions))
declarator: (variable_declarator
name: (identifier)
value: (method_invocation
object: (method_invocation
name: (identifier)
arguments: (argument_list))
name: (identifier)
arguments: (argument_list)))))
(local_variable_declaration_statement (local_variable_declaration
type: (array_type
element: (type_identifier)
dimensions: (dimensions))
declarator: (variable_declarator
name: (identifier)
value: (array_creation_expression
type: (type_identifier)
dimensions: (dimensions_expr (hex_integer_literal))
dimensions: (dimensions))))))
==========
module
===
==========

@@ -50,5 +79,5 @@ module com.foo { }

===
==============================
module with normal annotation
===
==============================

@@ -67,14 +96,14 @@ @RequestForEnhancement(

(module_declaration
(normal_annotation
(annotation
(identifier)
(element_value_pair_list
(element_value_pair (identifier) (element_value (integer_literal (decimal_integer_literal))))
(element_value_pair (identifier) (element_value (string_literal)))
(element_value_pair (identifier) (element_value (string_literal)))
(element_value_pair (identifier) (element_value (string_literal)))))
(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))))
(scoped_identifier (identifier) (identifier))))
===
==============================
module with marker annotation
===
==============================

@@ -90,5 +119,5 @@ @Preliminary module com.foo { }

===
======================================
module with single element annotation
===
======================================

@@ -101,6 +130,5 @@ @Copyright("a") module com.foo { }

(module_declaration
(single_element_annotation
(annotation
(identifier)
(element_value
(string_literal)))
(annotation_argument_list (string_literal)))
(scoped_identifier

@@ -110,5 +138,5 @@ (identifier)

===
====================
package_declaration
===
====================

@@ -121,5 +149,5 @@ package myVector;

===
=================
module directive
===
=================

@@ -141,5 +169,5 @@ module com.example.foo {

===
==================================================================
module directive with requires, exports, opens, uses and provides
===
==================================================================

@@ -162,2 +190,3 @@ module com.example.foo {

}
---

@@ -192,5 +221,5 @@

===
===============================
single type import declaration
===
===============================

@@ -203,5 +232,5 @@ import java.util.Vector;

===
===========================
type_import_on_declaraction
===
===========================

@@ -214,5 +243,5 @@ import java.util.*;

===
=================================
single static import declaration
===
=================================

@@ -225,5 +254,5 @@ import static java.util.Vector;

===
===================================
static import on demand declaration
===
===================================

@@ -236,5 +265,5 @@ import static java.util.*;

===
=================
class declaration
===
=================

@@ -251,5 +280,5 @@ class Point {

===
=====================================================================
class declaration involving public, private, abstract and superclass
===
=====================================================================

@@ -268,9 +297,9 @@ public class Point {

(program
(class_declaration (modifier) (identifier) (class_body))
(class_declaration (modifier) (identifier) (class_body))
(class_declaration (modifier) (identifier) (superclass (type_identifier)) (class_body)))
(class_declaration (modifiers) (identifier) (class_body))
(class_declaration (modifiers) (identifier) (class_body))
(class_declaration (modifiers) (identifier) (superclass (type_identifier)) (class_body)))
===
==================================
class declaration with implements
===
==================================

@@ -284,8 +313,8 @@ public class Dog implements ISpeak {

(class_declaration
(modifier) (identifier)
(modifiers) (identifier)
(super_interfaces (interface_type_list (type_identifier))) (class_body)))
===
============================
class declaration with body
===
============================

@@ -302,7 +331,20 @@ class Point {

(program (class_declaration (identifier) (class_body (field_declaration (integral_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier))))) (method_declaration (method_header (void_type) (method_declarator (identifier))) (method_body (block (assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))))))))
(program
(class_declaration
(identifier)
(class_body
(field_declaration
(integral_type)
(variable_declarator (identifier)))
(method_declaration
(void_type)
(identifier)
(formal_parameters)
(block
(expression_statement
(assignment_expression (identifier) (decimal_integer_literal))))))))
===
======================
interface declaration
===
======================

@@ -316,7 +358,8 @@ interface Top {

(interface_declaration
(normal_interface_declaration (identifier) (interface_body))))
(identifier)
(interface_body)))
===
===================================
interface declaration with extends
===
===================================

@@ -332,11 +375,12 @@ interface Left extends Top {

(interface_declaration
(normal_interface_declaration (identifier)
(extends_interfaces (interface_type_list (type_identifier))) (interface_body)))
(identifier)
(extends_interfaces (interface_type_list (type_identifier)))
(interface_body))
(interface_declaration
(normal_interface_declaration (identifier)
(extends_interfaces (interface_type_list (type_identifier) (type_identifier))) (interface_body))))
(identifier)
(extends_interfaces (interface_type_list (type_identifier) (type_identifier))) (interface_body)))
===
===========================================
interface with annotation type declaration
===
===========================================

@@ -348,11 +392,11 @@ @interface SelfRef {}

(program
(interface_declaration (annotation_type_declaration (identifier) (annotation_type_body))))
(annotation_type_declaration (identifier) (annotation_type_body)))
===
===================
method declaration
===
===================
class Beyonce {
void calculateAnswer(double wingSpan, int numberOfEngines,
double length, double grossTons) {
double length, double grossTons) {
//do the calculation here

@@ -364,11 +408,30 @@ }

(program (class_declaration (identifier) (class_body (method_declaration (method_header (void_type) (method_declarator (identifier) (formal_parameter (floating_point_type) (variable_declarator_id (identifier))) (formal_parameter (integral_type) (variable_declarator_id (identifier))) (formal_parameter (floating_point_type) (variable_declarator_id (identifier))) (formal_parameter (floating_point_type) (variable_declarator_id (identifier))))) (method_body (block (comment)))))))
(program
(class_declaration
(identifier)
(class_body
(method_declaration
(void_type)
(identifier)
(formal_parameters
(formal_parameter (floating_point_type) (identifier))
(formal_parameter (integral_type) (identifier))
(formal_parameter (floating_point_type) (identifier))
(formal_parameter (floating_point_type) (identifier)))
(block (comment))))))
===
========================
constructor declaration
===
========================
class Point {
int x, y;
Point(int x, int y) { this.x = x; this.y = y; }
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
Point() {
this(0, 0);
}
}

@@ -378,12 +441,48 @@

(program (class_declaration (identifier) (class_body (field_declaration (integral_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier))) (variable_declarator (variable_declarator_id (identifier))))) (constructor_declaration (constructor_declarator (identifier) (formal_parameter (integral_type) (variable_declarator_id (identifier))) (formal_parameter (integral_type) (variable_declarator_id (identifier)))) (constructor_body (assignment_expression (lhs (field_access (this) (identifier))) (identifier)) (assignment_expression (lhs (field_access (this) (identifier))) (identifier)))))))
(program
(class_declaration
name: (identifier)
body: (class_body
(field_declaration
type: (integral_type)
declarator: (variable_declarator name: (identifier))
declarator: (variable_declarator name: (identifier)))
(constructor_declaration
name: (identifier)
parameters: (formal_parameters
(formal_parameter
type: (integral_type)
name: (identifier))
(formal_parameter
type: (integral_type)
name: (identifier)))
body: (constructor_body
(expression_statement (assignment_expression
left: (field_access
object: (this)
field: (identifier))
right: (identifier)))
(expression_statement (assignment_expression
left: (field_access
object: (this)
field: (identifier))
right: (identifier)))))
(constructor_declaration
name: (identifier)
parameters: (formal_parameters)
body: (constructor_body
(explicit_constructor_invocation
constructor: (this)
arguments: (argument_list
(decimal_integer_literal)
(decimal_integer_literal))))))))
===
=======
throws
===
=======
class Beyonce {
BufferedReader newReader() throws FileNotFoundException {
new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
}
new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
}
}

@@ -398,35 +497,27 @@

(method_declaration
(method_header
(type_identifier)
(method_declarator
(identifier))
(throws
(exception_type_list
(exception_type
(type_identifier)))))
(method_body
(block
(class_instance_creation_expression
(unqualified_class_instance_creation_expression
(type_identifier)
(type_identifier)
(identifier)
(formal_parameters)
(throws (type_identifier))
(block
(expression_statement
(object_creation_expression
(type_identifier)
(argument_list
(class_instance_creation_expression
(unqualified_class_instance_creation_expression
(type_identifier)
(argument_list
(class_instance_creation_expression
(unqualified_class_instance_creation_expression
(type_identifier)
(argument_list
(identifier))))
(identifier)))))))))))))
(object_creation_expression
(type_identifier)
(argument_list
(object_creation_expression
(type_identifier)
(argument_list (identifier)))
(identifier)))))))))))
===
======================
object instantiation
===
======================
class Point {
public double Foo() {
new BufferedWriter();
Foo.new BufferedWriter();
}

@@ -442,15 +533,20 @@ }

(method_declaration
(modifier)
(method_header
(floating_point_type)
(method_declarator
(identifier)))
(method_body
(block
(class_instance_creation_expression
(unqualified_class_instance_creation_expression
(type_identifier)))))))))
===
(modifiers)
(floating_point_type)
(identifier)
(formal_parameters)
(block
(expression_statement
(object_creation_expression
(type_identifier)
(argument_list)))
(expression_statement
(object_creation_expression
(identifier)
(type_identifier)
(argument_list))))))))
=====================
variable declaration
===
=====================

@@ -470,19 +566,16 @@ class JayZ {

(method_declaration
(modifier)
(method_header
(void_type)
(method_declarator
(identifier)))
(method_body
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id (identifier))))))))))))
(modifiers)
(void_type)
(identifier)
(formal_parameters)
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator
(identifier)))))))))
===
=================
enum declaration
===
=================

@@ -495,2 +588,8 @@ enum HandSign {

(program (enum_declaration (identifier) (enum_constant (identifier)) (enum_constant (identifier)) (enum_constant (identifier))))
(program
(enum_declaration
name: (identifier)
body: (enum_body
(enum_constant name: (identifier))
(enum_constant name: (identifier))
(enum_constant name: (identifier)))))

@@ -1,4 +0,4 @@

===
==================================
standalone assignment expression
===
==================================

@@ -10,9 +10,9 @@ x = 3;

(program
(assignment_expression
(lhs (identifier))
(integer_literal (decimal_integer_literal))))
(expression_statement (assignment_expression
(identifier)
(decimal_integer_literal))))
===
==================================
standalone binary expression
===
==================================

@@ -42,25 +42,46 @@ a > b;

(program
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (identifier) (identifier))
(binary_expression (integer_literal (decimal_integer_literal)) (integer_literal (decimal_integer_literal)))
(binary_expression (integer_literal (decimal_integer_literal)) (integer_literal (decimal_integer_literal)))
(binary_expression (integer_literal (decimal_integer_literal)) (integer_literal (decimal_integer_literal)))
(binary_expression (integer_literal (decimal_integer_literal)) (integer_literal (decimal_integer_literal))))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (identifier) (identifier)))
(expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
(expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
(expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
(expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal))))
============================
==================================
instanceof expressions
==================================
a instanceof C.D;
a instanceof List<B>;
c instanceof C[];
---
(program
(expression_statement (instanceof_expression
(identifier)
(scoped_type_identifier (type_identifier) (type_identifier))))
(expression_statement (instanceof_expression
(identifier)
(generic_type (type_identifier) (type_arguments (type_identifier)))))
(expression_statement (instanceof_expression
(identifier)
(array_type (type_identifier) (dimensions)))))
===========================================================
if statements
============================
===========================================================

@@ -73,8 +94,9 @@ if (x)

(program
(if_then_else_statement
(identifier) (identifier)))
(if_statement
condition: (parenthesized_expression (identifier))
consequence: (expression_statement (identifier))))
============================
===========================================================
if statements with braces
============================
===========================================================

@@ -88,8 +110,9 @@ if (x) {

(program
(if_then_else_statement
(identifier) (block (identifier))))
(if_statement
condition: (parenthesized_expression (identifier))
consequence: (block (expression_statement (identifier)))))
============================
===========================================================
if statements with assignment without braces
============================
===========================================================

@@ -102,38 +125,15 @@ if (x = 3)

(program
(if_then_else_statement
(assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))
(assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))))
(if_statement
condition: (parenthesized_expression
(assignment_expression
left: (identifier)
right: (decimal_integer_literal)))
consequence: (expression_statement
(assignment_expression
left: (identifier)
right: (decimal_integer_literal)))))
============================
if statements with assignment with braces
============================
if (x = 3) {
y = 2;
}
---
(program
(if_then_else_statement
(assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))
(block
(assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal))))))
===
if statement without braces and one assignment in the then
===
if (x)
y = 3;
---
(program
(if_then_else_statement
(identifier) (assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))))
===
==================================
if then else statement
===
==================================

@@ -149,10 +149,19 @@ if (x = 3) {

(program
(if_then_else_statement
(assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))
(block (assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal))))
(block (assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal))))))
(if_statement
condition: (parenthesized_expression
(assignment_expression
left: (identifier)
right: (decimal_integer_literal)))
consequence: (block
(expression_statement (assignment_expression
left: (identifier)
right: (decimal_integer_literal))))
alternative: (block
(expression_statement (assignment_expression
left: (identifier)
right: (decimal_integer_literal))))))
===
==================================
nested if then else statements
===
==================================

@@ -168,12 +177,12 @@ if (a)

(program
(if_then_else_statement
(identifier)
(if_then_else_statement
(identifier)
(method_invocation (identifier))
(method_invocation (identifier)))))
(if_statement
(parenthesized_expression (identifier))
(if_statement
(parenthesized_expression (identifier))
(expression_statement (method_invocation (identifier) (argument_list)))
(expression_statement (method_invocation (identifier) (argument_list))))))
===
if-then shorthand
===
==================================
ternary expressions
==================================

@@ -185,25 +194,73 @@ max = (a > b) ? a : b;

(program
(assignment_expression (lhs (identifier))
(ternary_expression
(binary_expression (identifier) (identifier)) (identifier) (identifier))))
(expression_statement (assignment_expression
left: (identifier)
right: (ternary_expression
condition: (parenthesized_expression (binary_expression
left: (identifier)
right: (identifier)))
consequence: (identifier)
alternative: (identifier)))))
===
==================================
for statement
===
==================================
class ForDemo {
public static void main(String[] args){
for(int i=1; i<11; i++){
System.out.println("Count is: " + i);
}
}
for(int i = 1; i < 11; i++) {
System.out.println("Count is: " + i);
}
for (j.init(i); j.check(); j.update()) {
System.out.println(j);
}
---
(program (class_declaration (identifier) (class_body (method_declaration (modifier) (modifier) (method_header (void_type) (method_declarator (identifier) (formal_parameter (array_type (type_identifier) (dims)) (variable_declarator_id (identifier))))) (method_body (block (for_statement (basic_for_statement (for_init (local_variable_declaration (integral_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier)) (integer_literal (decimal_integer_literal)))))) (binary_expression (identifier) (integer_literal (decimal_integer_literal))) (update_expression (identifier)) (block (method_invocation (scoped_identifier (identifier) (identifier)) (identifier) (argument_list (binary_expression (string_literal) (identifier)))))))))))))
(program
(for_statement
(for_init
(local_variable_declaration
(integral_type)
(variable_declarator
(identifier)
(decimal_integer_literal))))
(binary_expression (identifier) (decimal_integer_literal))
(update_expression (identifier))
(block
(expression_statement (method_invocation
(scoped_identifier (identifier) (identifier))
(identifier)
(argument_list (binary_expression (string_literal) (identifier)))))))
(for_statement
(for_init (method_invocation (identifier) (identifier) (argument_list (identifier))))
(method_invocation (identifier) (identifier) (argument_list))
(method_invocation (identifier) (identifier) (argument_list))
(block
(expression_statement (method_invocation
(scoped_identifier (identifier) (identifier))
(identifier)
(argument_list (identifier)))))))
===
================================
Enhanced for statements
================================
for (A b : c) {
d(b);
}
---
(program
(enhanced_for_statement
(type_identifier)
(identifier)
(identifier)
(block
(expression_statement (method_invocation
(identifier)
(argument_list (identifier)))))))
==================================
while statement
===
==================================

@@ -224,48 +281,37 @@ class WhileDemo {

(class_declaration
(identifier)
(class_body
name: (identifier)
body: (class_body
(method_declaration
(modifier)
(modifier)
(method_header
(void_type)
(method_declarator
(identifier)
(formal_parameter
(array_type
(type_identifier)
(dims))
(variable_declarator_id
(identifier)))))
(method_body
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))
(integer_literal
(decimal_integer_literal))))))
(while_statement
(binary_expression
(identifier)
(integer_literal
(decimal_integer_literal)))
(block
(method_invocation
(scoped_identifier
(identifier) (identifier))
(identifier)
(argument_list
(binary_expression
(string_literal)
(identifier))))
(update_expression
(identifier))))))))))
(modifiers)
type: (void_type)
name: (identifier)
parameters: (formal_parameters
(formal_parameter
type: (array_type
element: (type_identifier)
dimensions: (dimensions))
name: (identifier)))
body: (block
(local_variable_declaration_statement
(local_variable_declaration
type: (integral_type)
declarator: (variable_declarator
name: (identifier)
value: (decimal_integer_literal))))
(while_statement
condition: (parenthesized_expression
(binary_expression
left: (identifier)
right: (decimal_integer_literal)))
body: (block
(expression_statement (method_invocation
object: (scoped_identifier (identifier) (identifier))
name: (identifier)
arguments: (argument_list
(binary_expression left: (string_literal) right: (identifier)))))
(expression_statement (update_expression (identifier))))))))))
===
==================================
try-with-resources statements
===
==================================

@@ -278,22 +324,25 @@ try (FileInputStream input = new FileInputStream("file.txt")) {

(program (try_statement (try_with_resources_statement (resource_specification (resource (type_identifier) (variable_declarator_id (identifier)) (class_instance_creation_expression (unqualified_class_instance_creation_expression (type_identifier) (argument_list (string_literal)))))) (block (local_variable_declaration_statement (local_variable_declaration (integral_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier)) (method_invocation (identifier) (identifier))))))))))
(program
(try_with_resources_statement
resources: (resource_specification
(resource
type: (type_identifier)
name: (identifier)
value: (object_creation_expression
type: (type_identifier)
arguments: (argument_list (string_literal)))))
body: (block
(local_variable_declaration_statement
(local_variable_declaration
type: (integral_type)
declarator: (variable_declarator
name: (identifier)
value: (method_invocation
object: (identifier)
name: (identifier)
arguments: (argument_list))))))))
===
assignment
===
class Beyonce {
public void four() {
x = 1;
}
}
---
(program (class_declaration (identifier) (class_body (method_declaration (modifier) (method_header (void_type) (method_declarator (identifier))) (method_body (block (assignment_expression (lhs (identifier)) (integer_literal (decimal_integer_literal)))))))))
===
==================================
return statement
===
==================================

@@ -310,8 +359,8 @@ return x;

(return_statement (binary_expression (identifier) (identifier)))
(return_statement (binary_expression (identifier) (integer_literal (decimal_integer_literal))))
(return_statement (binary_expression (identifier) (decimal_integer_literal)))
(return_statement (method_invocation (identifier) (argument_list (identifier)))))
===
normal_annotation
===
==================================
annotation
==================================

@@ -328,24 +377,21 @@ @SuppressWarnings(value = "unchecked")

(class_declaration
(modifier
(normal_annotation
(modifiers
(annotation
(identifier)
(element_value_pair_list
(annotation_argument_list
(element_value_pair
(identifier)
(element_value
(string_literal))))))
(modifier
(normal_annotation
(string_literal))))
(annotation
(identifier)
(element_value_pair_list
(annotation_argument_list
(element_value_pair
(identifier)
(element_value
(boolean_literal (true)))))))
(true)))))
(identifier)
(class_body)))
===
==================================
marker annotation
===
==================================

@@ -362,7 +408,17 @@ @Override

(program (class_declaration (modifier (marker_annotation (identifier))) (identifier) (class_body (method_declaration (modifier (marker_annotation (identifier))) (modifier) (method_header (void_type) (method_declarator (identifier))) (method_body (block))))))
(program
(class_declaration
(modifiers (marker_annotation (identifier)))
(identifier)
(class_body
(method_declaration
(modifiers (marker_annotation (identifier)))
(void_type)
(identifier)
(formal_parameters)
(block)))))
===
==================================
single element annotation
===
==================================

@@ -377,12 +433,19 @@ @Duck(waddle.swim)

(program (class_declaration (modifier (single_element_annotation (identifier) (element_value (scoped_identifier (identifier) (identifier))))) (modifier (single_element_annotation (identifier) (element_value (string_literal)))) (identifier) (class_body)))
(program
(class_declaration
(modifiers
(annotation (identifier) (annotation_argument_list (scoped_identifier (identifier) (identifier))))
(annotation (identifier) (annotation_argument_list (string_literal))))
(identifier)
(class_body)))
===
==================================
lambda expression
===
==================================
class LambdaTest {
void singleton() {
version -> create;
}
void singleton() {
version -> create;
(a, b) -> a + b;
}
}

@@ -392,25 +455,38 @@

(program (class_declaration (identifier) (class_body (method_declaration (method_header (void_type) (method_declarator (identifier))) (method_body (block (lambda_expression (identifier) (lambda_body (identifier)))))))))
(program
(class_declaration
(identifier)
(class_body
(method_declaration
(void_type)
(identifier)
(formal_parameters)
(block
(expression_statement (lambda_expression
(identifier)
(identifier)))
(expression_statement (lambda_expression
(inferred_parameters (identifier) (identifier))
(binary_expression (identifier) (identifier)))))))))
===
==================================
switch statement
===
==================================
public class SwitchDemo {
public static void main(String[] args) {
int destinysChild = 2;
String destinysChildString;
switch (destinysChild) {
case 1: destinysChildString = "Beyonce";
break;
case 2: destinysChildString = "Kelly";
break;
case 3: destinysChildString = "Michelle";
break;
default: destinysChildString = "Invalid";
break;
}
System.out.println(destinysChildString);
public static void main(String[] args) {
int destinysChild = 2;
String destinysChildString;
switch (destinysChild) {
case 1: destinysChildString = "Beyonce";
break;
case 2: destinysChildString = "Kelly";
break;
case 3: destinysChildString = "Michelle";
break;
default: destinysChildString = "Invalid";
break;
}
System.out.println(destinysChildString);
}
}

@@ -420,7 +496,59 @@

(program (class_declaration (modifier) (identifier) (class_body (method_declaration (modifier) (modifier) (method_header (void_type) (method_declarator (identifier) (formal_parameter (array_type (type_identifier) (dims)) (variable_declarator_id (identifier))))) (method_body (block (local_variable_declaration_statement (local_variable_declaration (integral_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier)) (integer_literal (decimal_integer_literal)))))) (local_variable_declaration_statement (local_variable_declaration (type_identifier) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier)))))) (switch_statement (identifier) (switch_block (switch_label (integer_literal (decimal_integer_literal))) (assignment_expression (lhs (identifier)) (string_literal)) (break_statement) (switch_label (integer_literal (decimal_integer_literal))) (assignment_expression (lhs (identifier)) (string_literal)) (break_statement) (switch_label (integer_literal (decimal_integer_literal))) (assignment_expression (lhs (identifier)) (string_literal)) (break_statement) (switch_label) (assignment_expression (lhs (identifier)) (string_literal)) (break_statement))) (method_invocation (scoped_identifier (identifier) (identifier)) (identifier) (argument_list (identifier)))))))))
(program
(class_declaration
(modifiers)
name: (identifier)
body: (class_body
(method_declaration
(modifiers)
type: (void_type)
name: (identifier)
parameters: (formal_parameters
(formal_parameter
type: (array_type
element: (type_identifier)
dimensions: (dimensions))
name: (identifier)))
body: (block
(local_variable_declaration_statement
(local_variable_declaration
type: (integral_type)
declarator: (variable_declarator
name: (identifier)
value: (decimal_integer_literal))))
(local_variable_declaration_statement
(local_variable_declaration
type: (type_identifier)
declarator: (variable_declarator name: (identifier))))
(switch_statement
condition: (parenthesized_expression (identifier))
body: (switch_block
(switch_label (decimal_integer_literal))
(expression_statement (assignment_expression
left: (identifier)
right: (string_literal)))
(break_statement)
(switch_label (decimal_integer_literal))
(expression_statement (assignment_expression
left: (identifier)
right: (string_literal)))
(break_statement)
(switch_label (decimal_integer_literal))
(expression_statement (assignment_expression
left: (identifier)
right: (string_literal)))
(break_statement)
(switch_label)
(expression_statement (assignment_expression
left: (identifier)
right: (string_literal)))
(break_statement)))
(expression_statement (method_invocation
object: (scoped_identifier (identifier) (identifier))
name: (identifier)
arguments: (argument_list (identifier)))))))))
===
==================================
type arguments
===
==================================

@@ -443,25 +571,21 @@ class Box <T> {

(field_declaration
(modifier)
(modifiers)
(type_identifier)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier)))))
(constructor_declaration
(modifier)
(constructor_declarator
(identifier)
(formal_parameter
(type_identifier)
(variable_declarator_id
(identifier))))
(constructor_body
(assignment_expression
(lhs (identifier))
(identifier))))
(comment))))
(variable_declarator (identifier)))
(constructor_declaration
(modifiers)
(identifier)
(formal_parameters
(formal_parameter
(type_identifier)
(identifier)))
(constructor_body
(expression_statement (assignment_expression
(identifier)
(identifier)))))
(comment))))
===
==================================
wildcard
===
==================================

@@ -481,13 +605,9 @@ class WildcardDemo {

(type_identifier)
(type_argument
(wildcard
(type_identifier))))
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))))
(type_arguments
(wildcard (type_identifier))))
(variable_declarator (identifier))))))
===
==================================
type arguments with generic types
===
==================================

@@ -514,58 +634,50 @@ class someClass <T> {

(method_declaration
(modifier)
(method_header
(generic_type
(modifiers)
(generic_type
(type_identifier)
(type_arguments (type_identifier)))
(identifier)
(formal_parameters)
(block
(local_variable_declaration_statement
(local_variable_declaration
(generic_type
(type_identifier)
(type_arguments (type_identifier)))
(variable_declarator
(identifier)
(method_invocation
(identifier)
(type_arguments (type_identifier))
(identifier)
(argument_list)))))
(return_statement (identifier))))
(method_declaration
(modifiers)
(type_parameters
(type_parameter
(identifier)))
(void_type)
(identifier)
(formal_parameters
(formal_parameter
(type_identifier)
(type_argument
(type_identifier)))
(method_declarator
(identifier)))
(method_body
(block
(binary_expression
(binary_expression
(block
(local_variable_declaration_statement
(local_variable_declaration
(generic_type
(type_identifier)
(type_arguments (type_identifier)))
(variable_declarator
(identifier)
(identifier))
(assignment_expression
(lhs
(identifier))
(method_invocation
(identifier)
(type_argument
(type_identifier))
(identifier))))
(return_statement
(identifier)))))
(method_declaration
(modifier)
(modifier)
(method_header
(type_parameters
(type_parameter
(identifier)))
(void_type)
(method_declarator
(identifier)
(formal_parameter
(type_identifier)
(variable_declarator_id
(identifier)))))
(method_body
(block
(binary_expression
(binary_expression
(identifier)
(identifier))
(assignment_expression
(lhs
(identifier))
(method_invocation
(identifier)
(type_argument
(type_identifier))
(identifier))))))))))
(type_arguments (type_identifier))
(identifier)
(argument_list))))))))))
===
==================================
empty type arguments
===
==================================

@@ -576,2 +688,28 @@ Box<Integer> integerBox = new Box<>();

(program (binary_expression (binary_expression (identifier) (identifier)) (assignment_expression (lhs (identifier)) (class_instance_creation_expression (unqualified_class_instance_creation_expression (generic_type (type_identifier)))))))
(program
(local_variable_declaration_statement (local_variable_declaration
(generic_type (type_identifier) (type_arguments (type_identifier)))
(variable_declarator
(identifier)
(object_creation_expression
(generic_type (type_identifier) (type_arguments))
(argument_list))))))
=================
method references
=================
action = bar::method;
foo.bar::method;
String[]::new;
Foo<T>::apply;
super::something;
---
(program
(expression_statement (assignment_expression (identifier) (method_reference (identifier) (identifier))))
(expression_statement (method_reference (scoped_identifier (identifier) (identifier)) (identifier)))
(expression_statement (method_reference (array_type (type_identifier) (dimensions))))
(expression_statement (method_reference (generic_type (type_identifier) (type_arguments (type_identifier))) (identifier)))
(expression_statement (method_reference (super) (identifier))))

@@ -1,25 +0,34 @@

=======
decimal integer literal
=======
========================
decimal integer literals
========================
123;
4l;
50L;
---
(program (integer_literal (decimal_integer_literal)))
(program
(expression_statement (decimal_integer_literal))
(expression_statement (decimal_integer_literal))
(expression_statement (decimal_integer_literal)))
=============
hex_integer_literal
=============
====================
hex integer literals
====================
0xa_bcd_ef0;
0Xa_bcd_ef0;
0X8000L;
---
(program (integer_literal (hex_integer_literal)) (integer_literal (hex_integer_literal)))
(program
(expression_statement (hex_integer_literal))
(expression_statement (hex_integer_literal))
(expression_statement (hex_integer_literal)))
========
octal_integer_literal
========
======================
octal integer literals
======================

@@ -31,7 +40,9 @@ 0o123;

(program (integer_literal (octal_integer_literal)) (integer_literal (octal_integer_literal)))
(program
(expression_statement (octal_integer_literal))
(expression_statement (octal_integer_literal)))
=======
binary_integer_literal
=======
=======================
binary integer literal
=======================

@@ -45,7 +56,11 @@ 0b001;

(program (integer_literal (binary_integer_literal)) (integer_literal (binary_integer_literal)) (integer_literal (binary_integer_literal)) (integer_literal (binary_integer_literal)))
(program
(expression_statement (binary_integer_literal))
(expression_statement (binary_integer_literal))
(expression_statement (binary_integer_literal))
(expression_statement (binary_integer_literal)))
======
decimal_floating_point_literal
======
===============================
floating point literals
===============================

@@ -64,10 +79,26 @@ 4.23e9;

.2e-2;
0x5.4;
0x5.4e-10;
---
(program (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)) (floating_point_literal (decimal_floating_point_literal)))
(program
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (hex_floating_point_literal))
(expression_statement (hex_floating_point_literal)))
====
boolean_literal
====
================
boolean literals
================

@@ -79,7 +110,9 @@ true;

(program (boolean_literal (true)) (boolean_literal (false)))
(program
(expression_statement (true))
(expression_statement (false)))
======
character_literal
======
===================
character literals
===================

@@ -98,7 +131,16 @@ 'a';

(program (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal))
(program
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal)))
=====
string literal
=====
===============
string literals
===============

@@ -112,7 +154,11 @@ "";

(program (string_literal) (string_literal) (string_literal) (string_literal))
(program
(expression_statement (string_literal))
(expression_statement (string_literal))
(expression_statement (string_literal))
(expression_statement (string_literal)))
======
null literal
======
=============
null literals
=============

@@ -123,3 +169,4 @@ null;

(program (null_literal))
(program
(expression_statement (null_literal)))

@@ -137,7 +184,15 @@ =========================================

'\'';
'\\';
'\\' + 'a';
---
(program (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal))
(program
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (binary_expression (character_literal) (character_literal))))

@@ -152,3 +207,4 @@ =========================================

(program (character_literal))
(program
(expression_statement (character_literal)))

@@ -163,7 +219,8 @@ =========================================

(program (character_literal))
(program
(expression_statement (character_literal)))
=======
ascii
=======
=================
ascii escapes
=================

@@ -205,2 +262,34 @@ '\NUL';

(program (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal) (character_literal))
(program
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal)))

@@ -1,4 +0,4 @@

===
===============
integral types
===
===============

@@ -17,3 +17,3 @@ class Beyonce {

(program
(program
(class_declaration

@@ -23,48 +23,31 @@ (identifier)

(method_declaration
(method_header
(integral_type)
(method_declarator
(identifier)))
(method_body
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator_list
(variable_declarator
(variable_declarator_id
(identifier))))))))))))
(integral_type)
(identifier)
(formal_parameters)
(block
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator (identifier))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator (identifier))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator (identifier))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator (identifier))))
(local_variable_declaration_statement
(local_variable_declaration
(integral_type)
(variable_declarator (identifier)))))))))
===
floating point type
===
=====================
floating point types
=====================

@@ -80,2 +63,18 @@ class Beyonce {

(program (class_declaration (identifier) (class_body (method_declaration (method_header (integral_type) (method_declarator (identifier))) (method_body (block (local_variable_declaration_statement (local_variable_declaration (floating_point_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier)))))) (local_variable_declaration_statement (local_variable_declaration (floating_point_type) (variable_declarator_list (variable_declarator (variable_declarator_id (identifier))))))))))))
(program
(class_declaration
(identifier)
(class_body
(method_declaration
(integral_type)
(identifier)
(formal_parameters)
(block
(local_variable_declaration_statement
(local_variable_declaration
(floating_point_type)
(variable_declarator (identifier))))
(local_variable_declaration_statement
(local_variable_declaration
(floating_point_type)
(variable_declarator (identifier)))))))))

@@ -23,3 +23,4 @@ const DIGITS = token(sep1(/[0-9]+/, /_+/))

CALL: 12,
MEMBER: 13
MEMBER: 13,
CAST: 15,
};

@@ -35,12 +36,22 @@

supertypes: $ => [
$._expression,
$._declaration,
$._statement,
$._literal,
$._primary,
$._type,
$._simple_type,
$._unannotated_type,
],
inline: $ => [
$.formal_parameters,
$._numeric_type,
$._block_statement,
$._ambiguous_name,
$._class_or_interface_type,
$._primitive_type,
$._simple_type,
$._reserved_identifier,
$._class_member_declaration,
$._interface_member_declaration,
$._annotation_type_member_declaration,
$._class_body_declaration,
$._parenthesized_argument_list,
$._variable_initializer

@@ -50,16 +61,13 @@ ],

conflicts: $ => [
[$.modifier],
[$.class_literal, $._unann_type], // TODO: remove
[$._unann_type, $.class_literal, $.array_access],
[$.unann_class_or_interface_type, $.method_reference],
[$.unann_class_or_interface_type, $.scoped_identifier],
[$.constant_declaration, $.local_variable_declaration],
[$.variable_declarator_id],
[$._lambda_parameters, $.inferred_parameters],
[$._expression, $.inferred_parameters],
[$._expression, $.inferred_parameters, $._unann_type], // TODO: remove (can't occur alone)
[$._expression, $._unann_type],
[$.modifiers, $.annotated_type, $.receiver_parameter],
[$.modifiers, $.annotated_type, $.module_declaration, $.package_declaration],
[$._variable_declarator_id],
[$._unannotated_type, $._expression],
[$._unannotated_type, $._expression, $.inferred_parameters],
[$._unannotated_type, $.class_literal],
[$._unannotated_type, $.class_literal, $.array_access],
[$._unannotated_type, $.method_reference],
[$._unannotated_type, $.generic_type],
[$._expression, $.generic_type],
[$.scoped_identifier, $.scoped_type_identifier],
[$._expression, $.generic_type],
[$._expression, $.for_init] // TODO: remove to allow non variable declarations in for_init to parse
],

@@ -72,43 +80,5 @@

_statement: $ => prec(1, choice(
$._expression_statement,
$._declaration,
$._method_statement
)),
// Literals
_method_statement: $ => choice(
$.labeled_statement,
$.if_then_else_statement,
$.while_statement,
$.for_statement,
$.block,
$._semicolon,
$.assert_statement,
$.switch_statement,
$.do_statement,
$.break_statement,
$.continue_statement,
$.return_statement,
$.synchronized_statement,
$.throw_statement,
$.try_statement
),
_expression_statement: $ => seq(
$._expression,
$._semicolon
),
_semicolon: $ => ';',
_literal: $ => choice(
$.integer_literal,
$.floating_point_literal,
$.boolean_literal,
$.character_literal,
$.string_literal,
$.null_literal
),
integer_literal: $ => choice(
$.decimal_integer_literal,

@@ -118,10 +88,20 @@ $.hex_integer_literal,

$.binary_integer_literal,
$.long_integer_literal
$.decimal_floating_point_literal,
$.hex_floating_point_literal,
$.true,
$.false,
$.character_literal,
$.string_literal,
$.null_literal
),
decimal_integer_literal: $ => DIGITS,
decimal_integer_literal: $ => token(seq(
DIGITS,
optional(choice('l', 'L'))
)),
hex_integer_literal: $ => token(seq(
choice('0x', '0X'),
HEX_DIGITS
choice('0x', '0X'),
HEX_DIGITS,
optional(choice('l', 'L'))
)),

@@ -131,28 +111,19 @@

choice('0o', '0O'),
sep1(/[0-7]+/, '_')
)),
sep1(/[0-7]+/, '_'),
optional(choice('l', 'L'))
)),
binary_integer_literal: $ => token(seq(
choice('0b', '0B'),
sep1(/[01]+/, '_')
sep1(/[01]+/, '_'),
optional(choice('l', 'L'))
)),
long_integer_literal: $ => token(seq(
sep1(/[0-9]+/, '_'),
choice('l', 'L'),
decimal_floating_point_literal: $ => token(choice(
seq(DIGITS, '.', optional(DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DIGITS)), optional(/[fFdD]/)),
seq('.', DIGITS, optional(seq((/[eE]/), optional(choice('-','+')), DIGITS)), optional(/[fFdD]/)),
seq(DIGITS, /[eEpP]/, optional(choice('-','+')), DIGITS, optional(/[fFdD]/)),
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-','+')), DIGITS)), (/[fFdD]/))
)),
floating_point_literal: $ => choice(
$.decimal_floating_point_literal,
$.hex_floating_point_literal
),
decimal_floating_point_literal: $ => token(
choice(
seq(DIGITS, '.', optional(DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DIGITS)), optional(/[fFdD]/)),
seq('.', DIGITS, optional(seq((/[eE]/), optional(choice('-','+')), DIGITS)), optional(/[fFdD]/)),
seq(DIGITS, /[eE]/, optional(choice('-','+')), DIGITS, optional(/[fFdD]/)),
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-','+')), DIGITS)), (/[fFdD]/))
)),
hex_floating_point_literal: $ => token(seq(

@@ -164,10 +135,10 @@ choice('0x', '0X'),

),
/[eE]/,
optional(choice('-','+')),
DIGITS,
optional(/[fFdD]/)
optional(seq(
/[eEpP]/,
optional(choice('-','+')),
DIGITS,
optional(/[fFdD]/)
))
)),
boolean_literal: $ => choice($.true, $.false),
true: $ => 'true',

@@ -177,3 +148,11 @@

character_literal: $ => seq("'", repeat(choice(/[^\'\n]/, /\\./, /\\\n/)), "'"),
character_literal: $ => token(seq(
"'",
repeat1(choice(
/[^\\'\n]/,
/\\./,
/\\\n/
)),
"'"
)),

@@ -188,96 +167,12 @@ string_literal: $ => token(choice(

ascii: $ => choice(
'NUL', // (null)
'SOH', // (start of heading)
'STX', // (start of text)
'ETX', // (end of text)
'EOT', // (end of transmission)
'ENQ', // (enquiry)
'ACK', // (acknowledge)
'BEL', // (bell)
'BS', // (backspace)
'TAB', // (horizontal tab)
'LF', // (NL line feed, new line)
'VT', // (vertical tab)
'FF', // (NP form feed, new page)
'CR', // (carriage return)
'SO', // (shift out)
'SI', // (shift in)
'DLE', // (data link escape)
'DC1', // (device control 1)
'DC2', // (device control 2)
'DC3', // (device control 3)
'DC4', // (device control 4)
'NAK', // (negative acknowledge)
'SYN', // (synchronous idle)
'ETB', // (end of trans. block)
'CAN', // (cancel)
'EM', // (end of medium)
'SUB', // (substitute)
'ESC', // (escape)
'FS', // (file separator)
'GS', // (group separator)
'RS', // (record separator)
'US' // (unit separator)
),
// Expressions
white_space: $ => choice(
$.space,
$.horizontal_tab,
$.form_feed,
$.line_terminator
),
space: $ => 'SP',
horizontal_tab: $ => 'HT',
form_feed: $ => 'FF',
line_terminator: $ => choice(
$.newline,
$.return,
seq($.return, $.newline)
),
newline: $ => 'LF',
return: $ => 'CR',
unicode_escape: $ => seq(
/\\/,
'u',
/[A-Fa-f0-9]+/,
/[A-Fa-f0-9]+/,
/[A-Fa-f0-9]+/,
/[A-Fa-f0-9]+/
),
escape_sequences: $ => choice(
$.char_escapes,
$.octal_escapes
),
// currently, literals.java returns char not char_escapes in tree
char_escapes: $ => choice(
'b',
't',
'n',
'f',
'r',
'"',
"'",
'\\'
),
octal_escapes: $ => choice(
seq(/\\/, /[0-7]+/),
seq(/\\/, /[0-7]+/, /[0-7]+/),
seq(/\\/, /[0-3]/, /[0-7]+/, /[0-7]+/)
),
_expression: $ => choice(
$.assignment_expression,
$.binary_expression,
$.instanceof_expression,
$.lambda_expression,
$.ternary_expression,
$.update_expression,
$._ambiguous_name,
prec.dynamic(1, $._ambiguous_name),
$._primary,

@@ -288,23 +183,19 @@ $.unary_expression,

cast_expression: $ => prec(15, choice(
seq('(', $._type, repeat($.additional_bound), ')', $._expression)
cast_expression: $ => prec(PREC.CAST, seq(
'(',
sep1(field('type', $._type), '&'),
')',
field('value', $._expression)
)),
additional_bound: $ => seq('&', $._type),
assignment_expression: $ => prec.right(PREC.ASSIGN, seq(
$.lhs,
choice('=', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '%=', '<<=', '>>=', '>>>='),
$._expression)
),
field('left', choice(
$._ambiguous_name,
$.field_access,
$.array_access
)),
field('operator', choice('=', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '%=', '<<=', '>>=', '>>>=')),
field('right', $._expression)
)),
lhs: $ => choice(
$._ambiguous_name,
$.field_access,
$.array_access
),
// NOTE: Precedence was added due to error and duplication with
// type_arguments.
// TODO: Verify precedence is legit.
binary_expression: $ => choice(

@@ -331,20 +222,22 @@ ...[

['>>>', PREC.TIMES],
['instanceof', PREC.REL]
].map(([operator, precedence]) =>
prec.left(precedence, seq(
$._expression,
operator,
$._expression
field('left', $._expression),
field('operator', operator),
field('right', $._expression)
))
)),
// TODO: test
// Lowest precedence operator is lambda arrow
// https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-Expression
lambda_expression: $ => seq($._lambda_parameters, '->', $.lambda_body),
instanceof_expression: $ => prec(PREC.REL, seq(
field('left', $._expression),
'instanceof',
field('right', $._type)
)),
_lambda_parameters: $ => choice(
$.identifier,
seq($.formal_parameters),
$.inferred_parameters
lambda_expression: $ => seq(
field('parameters', choice(
$.identifier, $.formal_parameters, $.inferred_parameters
)),
'->',
field('body', choice($._expression, $.block))
),

@@ -354,13 +247,12 @@

'(',
commaSep($.identifier),
commaSep1($.identifier),
')'
),
lambda_body: $ => choice(
$._expression,
$.block,
),
ternary_expression: $ => prec.right(PREC.TERNARY, seq(
$._expression, '?', $._expression, ':', $._expression
field('condition', $._expression),
'?',
field('consequence', $._expression),
':',
field('alternative', $._expression)
)),

@@ -374,6 +266,8 @@

].map(([operator, precedence]) =>
prec.left(precedence, seq(operator, $._expression))
prec.left(precedence, seq(
field('operator', operator),
field('operand', $._expression)
))
)),
// TODO: test this
update_expression: $ => prec.left(PREC.INC, choice(

@@ -386,2 +280,172 @@ seq($._expression, '++'),

_primary: $ => choice(
$._literal,
$.class_literal,
$.this,
$.parenthesized_expression,
$.object_creation_expression,
$.field_access,
$.array_access,
$.method_invocation,
$.method_reference,
$.array_creation_expression
),
array_creation_expression: $ => prec.right(seq(
'new',
field('type', $._simple_type),
choice(
seq(
field('dimensions', repeat1($.dimensions_expr)),
field('dimensions', optional($.dimensions))
),
seq(
field('dimensions', $.dimensions),
field('value', $.array_initializer)
)
)
)),
dimensions_expr: $ => seq(repeat($._annotation), '[', $._expression, ']'),
parenthesized_expression: $ => seq('(', $._expression, ')'),
class_literal: $ => choice(
seq($._ambiguous_name, repeat(seq('[', ']')), '.', 'class'),
seq($._numeric_type, repeat(seq('[', ']')), '.', 'class'),
seq($.boolean_type, repeat(seq('[', ']')), '.', 'class'),
seq($.void_type, '.', 'class')
),
object_creation_expression: $ => choice(
$._unqualified_object_creation_expression,
seq($._ambiguous_name, '.', $._unqualified_object_creation_expression),
seq($._primary, '.', $._unqualified_object_creation_expression)
),
_unqualified_object_creation_expression: $ => prec.right(seq(
'new',
field('type_arguments', optional($.type_arguments)),
field('type', $._simple_type),
field('arguments', $.argument_list),
optional($.class_body)
)),
field_access: $ => choice(
seq(
field('object', $._ambiguous_name),
'.',
field('field', $.this)
),
seq(
field('object', choice($._primary, $.super)),
'.',
field('field', $.identifier)
),
seq(
field('object', $._ambiguous_name),
'.',
$.super,
'.',
field('field', $.identifier)
)
),
array_access: $ => seq(
field('array', choice($._ambiguous_name, $._primary)),
'[',
field('index', $._expression),
']',
),
method_invocation: $ => seq(
choice(
field('name', choice($.identifier, $._reserved_identifier)),
seq(
field('object', choice(
$._ambiguous_name,
$._primary,
$.super,
$._ambiguous_name
)),
'.',
field('type_arguments', optional($.type_arguments)),
field('name', $.identifier),
),
seq(
field('object', $._ambiguous_name),
'.',
$.super,
'.',
field('type_arguments', optional($.type_arguments)),
field('name', $.identifier),
)
),
field('arguments', $.argument_list)
),
argument_list: $ => seq('(', commaSep($._expression), ')'),
method_reference: $ => seq(
choice($._type, $._ambiguous_name, $._primary, $.super),
'::',
optional($.type_arguments),
choice('new', $.identifier)
),
type_arguments: $ => seq(
'<',
commaSep(choice($._type, $.wildcard)),
'>'
),
wildcard: $ => seq(
repeat($._annotation),
'?',
optional($._wildcard_bounds)
),
_wildcard_bounds: $ => choice(
seq('extends', $._type),
seq($.super, $._type)
),
dimensions: $ => prec.right(repeat1(
seq(repeat($._annotation), '[', ']')
)),
// Statements
_statement: $ => choice(
$._declaration,
$.expression_statement,
$.labeled_statement,
$.if_statement,
$.while_statement,
$.for_statement,
$.enhanced_for_statement,
$.block,
';',
$.assert_statement,
$.switch_statement,
$.do_statement,
$.break_statement,
$.continue_statement,
$.return_statement,
$.synchronized_statement,
$.local_variable_declaration_statement,
$.throw_statement,
$.try_statement,
$.try_with_resources_statement
),
block: $ => seq(
'{', repeat($._statement), '}'
),
expression_statement: $ => seq(
$._expression,
';'
),
labeled_statement: $ => seq(

@@ -392,4 +456,4 @@ $.identifier, ':', $._statement

assert_statement: $ => choice(
seq('assert', $._expression, $._semicolon),
seq('assert', $._expression, ':', $._expression, $._semicolon)
seq('assert', $._expression, ';'),
seq('assert', $._expression, ':', $._expression, ';')
),

@@ -399,10 +463,9 @@

'switch',
'(', $._expression, ')',
$.switch_block
field('condition', $.parenthesized_expression),
field('body', $.switch_block)
),
// NOTE: switch_label precedes block_statement according to spec
switch_block: $ => seq(
'{',
repeat(choice($.switch_label, $._block_statement)),
repeat(choice($.switch_label, $._statement)),
'}'

@@ -417,8 +480,8 @@ ),

do_statement: $ => seq(
'do', $._statement, 'while', '(', $._expression, ')', $._semicolon
'do', $._statement, 'while', '(', $._expression, ')', ';'
),
break_statement: $ => seq('break', optional($.identifier), $._semicolon),
break_statement: $ => seq('break', optional($.identifier), ';'),
continue_statement: $ => seq('continue', optional($.identifier), $._semicolon),
continue_statement: $ => seq('continue', optional($.identifier), ';'),

@@ -428,3 +491,3 @@ return_statement: $ => seq(

optional($._expression),
$._semicolon
';'
),

@@ -434,30 +497,37 @@

throw_statement: $ => seq('throw', $._expression, $._semicolon),
throw_statement: $ => seq('throw', $._expression, ';'),
try_statement: $ => choice(
seq('try', $.block, $.catches),
seq('try', $.block, optional($.catches), $.finally),
$.try_with_resources_statement
try_statement: $ => seq(
'try',
field('body', $.block),
choice(
repeat1($.catch_clause),
seq(repeat($.catch_clause), $.finally_clause)
)
),
catches: $ => prec.right(repeat1($.catch_clause)),
catch_clause: $ => seq(
'catch',
'(',
$.catch_formal_parameter,
')',
field('body', $.block)
),
catch_clause: $ => seq('catch', '(', $.catch_formal_parameter, ')', $.block),
catch_formal_parameter: $ => seq(
repeat($.modifier),
optional($.modifiers),
$.catch_type,
$.variable_declarator_id
$._variable_declarator_id
),
catch_type: $ => seq($._unann_type, repeat(seq('|', $._type))),
catch_type: $ => sep1($._unannotated_type, '|'),
finally: $ => seq('finally', $.block),
finally_clause: $ => seq('finally', $.block),
try_with_resources_statement: $ => seq(
'try',
$.resource_specification,
$.block,
optional($.catches),
optional($.finally)
field('resources', $.resource_specification),
field('body', $.block),
repeat($.catch_clause),
optional($.finally_clause)
),

@@ -470,7 +540,9 @@

resource: $ => choice(
seq(repeat($.modifier), $._unann_type, $.variable_declarator_id, '=', $._expression),
$.variable_access
),
variable_access: $ => choice(
seq(
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_id,
'=',
field('value', $._expression)
),
$._ambiguous_name,

@@ -480,21 +552,21 @@ $.field_access

if_then_else_statement: $ => prec.right(seq(
'if', '(', $._expression, ')',
$._statement,
optional(seq('else', $._statement))
if_statement: $ => prec.right(seq(
'if',
field('condition', $.parenthesized_expression),
field('consequence', $._statement),
optional(seq('else', field('alternative', $._statement)))
)),
while_statement: $ => seq('while', '(', $._expression, ')', $._statement),
for_statement: $ => choice(
$.basic_for_statement,
$.enhanced_for_statement
while_statement: $ => seq(
'while',
field('condition', $.parenthesized_expression),
field('body', $._statement)
),
basic_for_statement: $ => seq(
for_statement: $ => seq(
'for', '(',
optional($.for_init), $._semicolon,
optional($._expression), $._semicolon,
optional($.for_init), ';',
optional($._expression), ';',
commaSep($._expression), ')',
$._method_statement
$._statement
),

@@ -510,91 +582,46 @@

'(',
repeat($.modifier),
$._unann_type,
$.variable_declarator_id,
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_id,
':',
$._expression,
field('value', $._expression),
')',
$._method_statement
field('body', $._statement)
),
_type_arguments_or_diamond: $ => choice(
$._type_arguments,
'<>'
),
// Annotations
_type_arguments: $ => seq(
'<', commaSep1($.type_argument), '>'
),
type_argument: $ => choice(
$._type,
$.wildcard
),
wildcard: $ => seq(
repeat($._annotation),
'?',
optional($._wildcard_bounds)
),
_wildcard_bounds: $ => choice(
seq('extends', $._type),
seq($.super, $._type)
),
dims: $ => prec.right(repeat1(
seq(repeat($._annotation), '[', ']')
)),
_numeric_type: $ => choice(
$.integral_type,
$.floating_point_type
),
integral_type: $ => choice(
'byte',
'short',
'int',
'long',
'char'
),
floating_point_type: $ => choice(
'float',
'double'
),
boolean_type: $ => 'boolean',
void_type: $ => 'void',
_annotation: $ => choice(
$.normal_annotation,
$.marker_annotation,
$.single_element_annotation
$.annotation
),
normal_annotation: $ => seq(
'@', $._ambiguous_name, '(', optional($.element_value_pair_list), ')',
marker_annotation: $ => seq(
'@',
field('name', choice($.identifier, $.scoped_identifier))
),
marker_annotation: $ => seq('@', $._ambiguous_name),
annotation: $ => seq(
'@',
field('name', choice($.identifier, $.scoped_identifier)),
field('arguments', $.annotation_argument_list)
),
// TODO: Replace choice($.identifier, $._literal) with $._statement once it's
// more fleshed out; The Java spec uses element_value which infinitely loops
single_element_annotation: $ => seq(
'@', $._ambiguous_name, '(', choice($.identifier, $._literal, $.scoped_identifier, $.element_value), ')'
annotation_argument_list: $ => seq(
'(',
choice(
$._element_value,
commaSep($.element_value_pair),
),
')'
),
element_value_pair_list: $ => commaSep1($.element_value_pair),
element_value_pair: $ => prec.right(10, seq(
$.identifier,
element_value_pair: $ => seq(
field('key', $.identifier),
'=',
$.element_value
)),
field('value', $._element_value)
),
element_value: $ => prec.left(1, choice(
$._literal,
$._ambiguous_name, // TODO: verify this, not accounted for in spec
_element_value: $ => prec(1, choice(
$._expression,
$.element_value_array_initializer,

@@ -604,9 +631,11 @@ $._annotation

element_value_array_initializer: $ => prec.left(seq(
element_value_array_initializer: $ => seq(
'{',
commaSep($.element_value),
commaSep($._element_value),
optional(','),
'}'
)),
),
// Declarations
_declaration: $ => prec(1, choice(

@@ -618,2 +647,3 @@ $.module_declaration,

$.interface_declaration,
$.annotation_type_declaration,
$.enum_declaration,

@@ -638,3 +668,3 @@ )),

seq('provides', $._ambiguous_name, 'with', $._ambiguous_name, repeat(seq(',', $._ambiguous_name)))
), $._semicolon),
), ';'),

@@ -655,3 +685,3 @@ requires_modifier: $ => choice(

$._ambiguous_name,
$._semicolon
';'
),

@@ -664,3 +694,3 @@

optional(seq('.', $.asterisk)),
$._semicolon
';'
),

@@ -671,6 +701,10 @@

enum_declaration: $ => seq(
repeat($.modifier),
optional($.modifiers),
'enum',
$.identifier,
optional($.super_interfaces),
field('name', $.identifier),
field('interfaces', optional($.super_interfaces)),
field('body', $.enum_body)
),
enum_body: $ => seq(
'{',

@@ -684,3 +718,3 @@ commaSep($.enum_constant),

enum_body_declarations: $ => seq(
$._semicolon,
';',
repeat($._class_body_declaration)

@@ -690,19 +724,19 @@ ),

enum_constant: $ => (seq(
repeat($.modifier),
$.identifier,
optional(seq('(', $.argument_list, ')')),
optional($.class_body)
optional($.modifiers),
field('name', $.identifier),
field('arguments', optional($.argument_list)),
field('body', optional($.class_body))
)),
class_declaration: $ => seq(
repeat($.modifier),
optional($.modifiers),
'class',
$.identifier,
optional($.type_parameters),
optional($.superclass),
optional($.super_interfaces),
$.class_body
field('name', $.identifier),
optional(field('type_parameters', $.type_parameters)),
optional(field('superclass', $.superclass)),
optional(field('interfaces', $.super_interfaces)),
field('body', $.class_body)
),
modifier: $ => choice(
modifiers: $ => repeat1(choice(
$._annotation,

@@ -721,3 +755,3 @@ 'public',

'volatile'
),
)),

@@ -770,12 +804,12 @@ type_parameters: $ => seq(

constructor_declaration: $ => seq(
repeat($.modifier),
$.constructor_declarator,
optional($.modifiers),
$._constructor_declarator,
optional($.throws),
$.constructor_body
field('body', $.constructor_body)
),
constructor_declarator: $ => seq(
optional($.type_parameters),
$.identifier,
$.formal_parameters
_constructor_declarator: $ => seq(
field('type_paramaters', optional($.type_parameters)),
field('name', $.identifier),
field('parameters', $.formal_parameters)
),

@@ -786,18 +820,28 @@

optional($.explicit_constructor_invocation),
repeat($._block_statement),
repeat($._statement),
'}'
),
explicit_constructor_invocation: $ => choice(
seq(optional($._type_arguments), $.this, $._parenthesized_argument_list, $._semicolon),
seq(optional($._type_arguments), $.super, $._parenthesized_argument_list, $._semicolon),
seq($._ambiguous_name, '.', optional($._type_arguments), $.super, $._parenthesized_argument_list, $._semicolon),
seq($._primary, '.', $.super, '(', optional($.argument_list), ')', $._semicolon)
explicit_constructor_invocation: $ => seq(
choice(
seq(
field('type_arguments', optional($.type_arguments)),
field('constructor', choice($.this, $.super)),
),
seq(
field('object', choice($._ambiguous_name, $._primary)),
'.',
field('type_arguments', optional($.type_arguments)),
field('constructor', $.super),
)
),
field('arguments', $.argument_list),
';'
),
_ambiguous_name: $ => prec(PREC.REL + 1, choice(
_ambiguous_name: $ => choice(
$.identifier,
$._reserved_identifier,
$.scoped_identifier
)),
),

@@ -815,143 +859,55 @@ scoped_identifier: $ => seq(

$.interface_declaration,
$.annotation_type_declaration,
$.enum_declaration,
$._semicolon
';'
),
field_declaration: $ => seq(
repeat($.modifier),
$._unann_type,
$.variable_declarator_list,
$._semicolon
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_list,
';'
),
_primary: $ => choice(
$._primary_no_new_array,
$.array_creation_expression
),
array_creation_expression: $ => seq(
'new',
choice($._primitive_type, $._class_or_interface_type),
choice(
seq($._dims_exprs, optional($.dims)),
seq($.dims, $.array_initializer)
)
),
// why didn't I just use a repeat1 here?
_dims_exprs: $ => prec.right(seq($.dims_expr, repeat($.dims_expr))),
dims_expr: $ => seq(repeat($._annotation), '[', $._expression, ']'),
_primary_no_new_array: $ => choice(
$._literal,
$.class_literal,
$.this,
seq($._ambiguous_name, '.', $.this),
seq('(', $._expression, ')'),
$.class_instance_creation_expression,
$.field_access,
$.array_access,
$.method_invocation,
$.method_reference
),
class_literal: $ => choice(
seq($._ambiguous_name, repeat(seq('[', ']')), '.', 'class'),
seq($._numeric_type, repeat(seq('[', ']')), '.', 'class'),
seq($.boolean_type, repeat(seq('[', ']')), '.', 'class'),
seq($.void_type, '.', 'class')
),
class_instance_creation_expression: $ => choice(
$.unqualified_class_instance_creation_expression,
seq($._ambiguous_name, '.', $.unqualified_class_instance_creation_expression),
seq($._primary, '.', $.unqualified_class_instance_creation_expression)
),
unqualified_class_instance_creation_expression: $ => prec.right(seq(
'new',
optional($._type_arguments),
choice($._primitive_type, $._class_or_interface_type),
'(', optional($.argument_list), ')',
optional($.class_body)
)),
field_access: $ => choice(
seq($._primary, '.', $.identifier),
seq($.super, '.', $.identifier),
seq($._ambiguous_name, '.', $.super, '.', $.identifier)
),
array_access: $ => choice(
seq($._ambiguous_name, '[', $._expression, ']'),
seq($._primary_no_new_array, '[', $._expression, ']')
),
method_invocation: $ => choice(
seq($.identifier, $._parenthesized_argument_list),
seq($._reserved_identifier, $._parenthesized_argument_list),
seq($._ambiguous_name, '.', optional($._type_arguments), $.identifier, $._parenthesized_argument_list),
seq($._primary, '.', optional($._type_arguments), $.identifier, $._parenthesized_argument_list),
seq($.super, '.', optional($._type_arguments), $.identifier, $._parenthesized_argument_list),
seq($._ambiguous_name, '.', $.super, '.', optional($._type_arguments), $.identifier, $._parenthesized_argument_list)
),
argument_list: $ => seq(
$._expression, repeat(seq(',', $._expression))
),
_parenthesized_argument_list: $ => seq('(', optional($.argument_list), ')'),
method_reference: $ => seq(
choice($._type, $._primary),
'::',
optional($._type_arguments),
choice('new', $.identifier)
),
interface_declaration: $ => choice(
$.normal_interface_declaration,
$.annotation_type_declaration
),
annotation_type_declaration: $ => seq(
repeat($.modifier),
'@', 'interface',
$.identifier,
$.annotation_type_body
optional($.modifiers),
'@interface',
field('name', $.identifier),
field('body', $.annotation_type_body)
),
annotation_type_body: $ => seq(
'{', repeat($.annotation_type_member_declaration), '}'
'{', repeat($._annotation_type_member_declaration), '}'
),
annotation_type_member_declaration: $ => choice(
_annotation_type_member_declaration: $ => choice(
$.annotation_type_element_declaration,
$.constant_declaration,
$.class_declaration,
$.interface_declaration
$.interface_declaration,
$.annotation_type_declaration
),
annotation_type_element_declaration: $ => seq(
repeat($.modifier),
$._unann_type,
$.identifier,
optional($.modifiers),
field('type', $._unannotated_type),
field('name', $.identifier),
'(', ')',
optional($.dims),
optional($.default_value),
$._semicolon
field('dimensions', optional($.dimensions)),
optional($._default_value),
';'
),
default_value: $ => seq(
'default', $.element_value
_default_value: $ => seq(
'default',
field('value', $._element_value)
),
normal_interface_declaration: $ => seq(
repeat($.modifier),
interface_declaration: $ => seq(
optional($.modifiers),
'interface',
$.identifier,
optional($.type_parameters),
field('name', $.identifier),
field('type_parameters', optional($.type_parameters)),
optional($.extends_interfaces),
$.interface_body
field('body', $.interface_body)
),

@@ -966,35 +922,35 @@

'{',
repeat($.interface_member_declaration),
repeat($._interface_member_declaration),
'}'
),
interface_member_declaration: $ => choice(
_interface_member_declaration: $ => choice(
$.constant_declaration,
$.enum_declaration,
$.method_declaration,
$.class_declaration,
$.interface_declaration,
$._semicolon
$.annotation_type_declaration,
';'
),
constant_declaration: $ => seq(
repeat($.modifier),
$._unann_type,
$.variable_declarator_list,
$._semicolon
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_list,
';'
),
// These are part of field declarations - variables of a class type are intro'd by field declarations
variable_declarator_list: $ => seq(
$.variable_declarator,
repeat(seq(',', $.variable_declarator))
_variable_declarator_list: $ => commaSep1(
field('declarator', $.variable_declarator)
),
variable_declarator: $ => seq(
$.variable_declarator_id,
optional(seq('=', $._variable_initializer))
$._variable_declarator_id,
optional(seq('=', field('value', $._variable_initializer)))
),
variable_declarator_id: $ => seq(
choice($.identifier, $._reserved_identifier),
optional($.dims)
_variable_declarator_id: $ => seq(
field('name', choice($.identifier, $._reserved_identifier)),
field('dimensions', optional($.dimensions))
),

@@ -1014,22 +970,19 @@

// Types
_type: $ => choice(
$._unann_type,
$._unannotated_type,
$.annotated_type
),
_unann_type: $ => choice(
$._primitive_type,
$.identifier,
$._class_or_interface_type,
_unannotated_type: $ => choice(
$._simple_type,
$.array_type
),
_primitive_type: $ => choice(
_simple_type: $ => choice(
$.void_type,
$._numeric_type,
$.boolean_type,
),
_class_or_interface_type: $ => choice(
prec(PREC.REL + 1, alias($.identifier, $.type_identifier)),
alias($.identifier, $.type_identifier),
$.scoped_type_identifier,

@@ -1041,3 +994,3 @@ $.generic_type

repeat1($._annotation),
$._unann_type
$._unannotated_type
),

@@ -1056,3 +1009,3 @@

generic_type: $ => prec(PREC.REL + 1, seq(
generic_type: $ => prec.dynamic(10, seq(
choice(

@@ -1062,21 +1015,48 @@ alias($.identifier, $.type_identifier),

),
$._type_arguments_or_diamond
$.type_arguments
)),
array_type: $ => seq(
$._unann_type,
$.dims
field('element', $._unannotated_type),
field('dimensions', $.dimensions)
),
method_header: $ => choice(
seq($._unann_type, $.method_declarator, optional($.throws)),
seq($.type_parameters, repeat($._annotation), $._unann_type, $.method_declarator, optional($.throws))
_numeric_type: $ => choice(
$.integral_type,
$.floating_point_type
),
method_declarator: $ => seq(
choice($.identifier, $._reserved_identifier),
$.formal_parameters,
optional($.dims)
integral_type: $ => choice(
'byte',
'short',
'int',
'long',
'char'
),
floating_point_type: $ => choice(
'float',
'double'
),
boolean_type: $ => 'boolean',
void_type: $ => 'void',
_method_header: $ => seq(
optional(seq(
field('type_parameters', $.type_parameters),
repeat($._annotation)
)),
field('type', $._unannotated_type),
$._method_declarator,
optional($.throws)
),
_method_declarator: $ => seq(
field('name', choice($.identifier, $._reserved_identifier)),
field('parameters', $.formal_parameters),
field('dimensions', optional($.dimensions))
),
formal_parameters: $ => seq(

@@ -1092,5 +1072,5 @@ '(',

formal_parameter: $ => seq(
repeat($.modifier),
$._unann_type,
$.variable_declarator_id
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_id
),

@@ -1100,3 +1080,3 @@

repeat($._annotation),
$._unann_type,
$._unannotated_type,
optional(seq($.identifier, '.')),

@@ -1107,4 +1087,4 @@ $.this

spread_parameter: $ => seq(
repeat($.modifier),
$._unann_type,
optional($.modifiers),
$._unannotated_type,
'...',

@@ -1114,49 +1094,21 @@ $.variable_declarator

last_formal_parameter: $ => choice(
$.spread_parameter,
$.formal_parameter
),
this: $ => 'this',
super: $ => 'super',
throws: $ => seq(
'throws', $.exception_type_list
'throws', commaSep1($._type)
),
exception_type_list: $ => commaSep1($.exception_type),
exception_type: $ => $._type,
method_body: $ => choice(
$.block,
$._semicolon
),
block: $ => seq(
'{', repeat($._block_statement), '}'
),
_block_statement: $ => choice(
$.local_variable_declaration_statement,
$.class_declaration,
$._statement
),
local_variable_declaration_statement: $ => seq(
$.local_variable_declaration,
$._semicolon
';'
),
local_variable_declaration: $ => seq(
repeat($.modifier),
$._unann_type,
$.variable_declarator_list
optional($.modifiers),
field('type', $._unannotated_type),
$._variable_declarator_list
),
method_declaration: $ => seq(
repeat($.modifier),
$.method_header,
$.method_body
optional($.modifiers),
$._method_header,
choice(field('body', $.block), ';')
),

@@ -1169,2 +1121,6 @@

this: $ => 'this',
super: $ => 'super',
identifier: $ => /[a-zA-Z_]\w*/,

@@ -1171,0 +1127,0 @@

@@ -10,1 +10,5 @@ try {

}
try {
module.exports.nodeTypeInfo = require("./src/node-types.json");
} catch (_) {}
{
"name": "tree-sitter-java",
"version": "0.13.0",
"version": "0.15.0",
"description": "Java grammar for tree-sitter",

@@ -17,7 +17,7 @@ "main": "index.js",

"dependencies": {
"nan": "^2.8.0"
"nan": "^2.12.1"
},
"devDependencies": {
"tree-sitter-cli": "^0.13.1",
"npm-watch": "^0.3.0"
"npm-watch": "^0.3.0",
"tree-sitter-cli": "^0.15.14"
},

@@ -24,0 +24,0 @@ "watch": {

@@ -8,3 +8,1 @@ tree-sitter-java

Java grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
Currently WIP — this is still in development.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc