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

tree-sitter-java

Package Overview
Dependencies
Maintainers
10
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.19.1 to 0.20.2

.github/pull_request_template.md

500

grammar.js

@@ -1,25 +0,29 @@

const DIGITS = token(sep1(/[0-9]+/, /_+/))
const DIGITS = token(choice('0', seq(/[1-9]/, optional(seq(optional('_'), sep1(/[0-9]+/, /_+/))))))
const DECIMAL_DIGITS = token(sep1(/[0-9]+/, '_'))
const HEX_DIGITS = token(sep1(/[A-Fa-f0-9]+/, '_'))
const PREC = {
COMMA: -1,
DECLARATION: 1,
COMMENT: 1,
ASSIGN: 0,
OBJECT: 1,
TERNARY: 1,
OR: 2,
AND: 3,
PLUS: 4,
REL: 5,
TIMES: 6,
TYPEOF: 7,
DELETE: 7,
VOID: 7,
NOT: 8,
NEG: 9,
INC: 10,
NEW: 11,
CALL: 12,
MEMBER: 13,
CAST: 15,
// https://introcs.cs.princeton.edu/java/11precedence/
COMMENT: 0, // // /* */
ASSIGN: 1, // = += -= *= /= %= &= ^= |= <<= >>= >>>=
DECL: 2,
ELEMENT_VAL: 2,
TERNARY: 3, // ?:
OR: 4, // ||
AND: 5, // &&
BIT_OR: 6, // |
BIT_XOR: 7, // ^
BIT_AND: 8, // &
EQUALITY: 9, // == !=
GENERIC: 10,
REL: 10, // < <= > >= instanceof
SHIFT: 11, // << >> >>>
ADD: 12, // + -
MULT: 13, // * / %
CAST: 14, // (Type)
OBJ_INST: 14, // new
UNARY: 15, // ++a --a a++ a-- + - ! ~
ARRAY: 16, // [Index]
OBJ_ACCESS: 16, // .
PARENS: 16, // (Expression)
CLASS_LITERAL: 17, // .
};

@@ -31,3 +35,4 @@

extras: $ => [
$.comment,
$.line_comment,
$.block_comment,
/\s/

@@ -45,2 +50,4 @@ ],

$._unannotated_type,
$.comment,
$.module_directive,
],

@@ -51,5 +58,4 @@

$._simple_type,
$._reserved_identifier,
$._class_body_declaration,
$._variable_initializer
$._variable_initializer,
],

@@ -66,2 +72,7 @@

[$.generic_type, $.primary_expression],
[$.expression, $.statement],
// Only conflicts in switch expressions
[$.lambda_expression, $.primary_expression],
[$.inferred_parameters, $.primary_expression],
[$.argument_list, $.record_pattern_body],
],

@@ -72,4 +83,9 @@

rules: {
program: $ => repeat($.statement),
program: $ => repeat($._toplevel_statement),
_toplevel_statement: $ => choice(
$.statement,
$.method_declaration,
),
// Literals

@@ -103,3 +119,3 @@

octal_integer_literal: $ => token(seq(
choice('0o', '0O'),
choice('0o', '0O', '0'),
sep1(/[0-7]+/, '_'),

@@ -116,6 +132,6 @@ optional(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]/))
seq(DECIMAL_DIGITS, '.', optional(DECIMAL_DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
seq('.', DECIMAL_DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
seq(DIGITS, /[eEpP]/, optional(choice('-', '+')), DECIMAL_DIGITS, optional(/[fFdD]/)),
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), (/[fFdD]/))
)),

@@ -131,3 +147,3 @@

/[eEpP]/,
optional(choice('-','+')),
optional(choice('-', '+')),
DIGITS,

@@ -143,3 +159,3 @@ optional(/[fFdD]/)

character_literal: $ => token(seq(
"'",
'\'',
repeat1(choice(

@@ -150,13 +166,56 @@ /[^\\'\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,
$.string_interpolation,
)),
'"'
),
_multiline_string_literal: $ => seq(
'"""',
repeat(choice(
alias($._multiline_string_fragment, $.multiline_string_fragment),
$._escape_sequence,
$.string_interpolation,
)),
'"""'
),
// 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.
null_literal: $ => 'null',
string_fragment: _ => token.immediate(prec(1, /[^"\\]+/)),
_multiline_string_fragment: _ => choice(
/[^"\\]+/,
seq(/"([^"\\]|\\")*/),
),
string_interpolation: $ => seq(
'\\{',
$.expression,
'}'
),
_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

@@ -173,10 +232,19 @@

$.unary_expression,
$.cast_expression
$.cast_expression,
$.switch_expression,
),
cast_expression: $ => prec(PREC.CAST, seq(
'(',
sep1(field('type', $._type), '&'),
')',
field('value', $.expression)
cast_expression: $ => prec(PREC.CAST, choice(
seq(
'(',
field('type', $._type),
')',
field('value', $.expression),
),
seq(
'(',
sep1(field('type', $._type), '&'),
')',
field('value', choice($.primary_expression, $.lambda_expression)),
),
)),

@@ -197,28 +265,28 @@

...[
['>', PREC.REL],
['<', PREC.REL],
['==', PREC.REL],
['>=', PREC.REL],
['<=', PREC.REL],
['!=', PREC.REL],
['&&', PREC.AND],
['||', PREC.OR],
['+', PREC.PLUS],
['-', PREC.PLUS],
['*', PREC.TIMES],
['/', PREC.TIMES],
['&', PREC.AND],
['|', PREC.OR],
['^', PREC.OR],
['%', PREC.TIMES],
['<<', PREC.TIMES],
['>>', PREC.TIMES],
['>>>', PREC.TIMES],
].map(([operator, precedence]) =>
prec.left(precedence, seq(
field('left', $.expression),
field('operator', operator),
field('right', $.expression)
))
)),
['>', PREC.REL],
['<', PREC.REL],
['>=', PREC.REL],
['<=', PREC.REL],
['==', PREC.EQUALITY],
['!=', PREC.EQUALITY],
['&&', PREC.AND],
['||', PREC.OR],
['+', PREC.ADD],
['-', PREC.ADD],
['*', PREC.MULT],
['/', PREC.MULT],
['&', PREC.BIT_AND],
['|', PREC.BIT_OR],
['^', PREC.BIT_XOR],
['%', PREC.MULT],
['<<', PREC.SHIFT],
['>>', PREC.SHIFT],
['>>>', PREC.SHIFT],
].map(([operator, precedence]) =>
prec.left(precedence, seq(
field('left', $.expression),
field('operator', operator),
field('right', $.expression)
))
)),

@@ -228,3 +296,10 @@ instanceof_expression: $ => prec(PREC.REL, seq(

'instanceof',
field('right', $._type)
optional('final'),
choice(
seq(
field('right', $._type),
optional(field('name', choice($.identifier, $._reserved_identifier))),
),
field('pattern', $.record_pattern),
),
)),

@@ -234,3 +309,3 @@

field('parameters', choice(
$.identifier, $.formal_parameters, $.inferred_parameters
$.identifier, $.formal_parameters, $.inferred_parameters, $._reserved_identifier
)),

@@ -243,3 +318,3 @@ '->',

'(',
commaSep1($.identifier),
commaSep1(choice($.identifier, $._reserved_identifier)),
')'

@@ -257,6 +332,6 @@ ),

unary_expression: $ => choice(...[
['+', PREC.NEG],
['-', PREC.NEG],
['!', PREC.NOT],
['~', PREC.NOT],
['+', PREC.UNARY],
['-', PREC.UNARY],
['!', PREC.UNARY],
['~', PREC.UNARY],
].map(([operator, precedence]) =>

@@ -269,3 +344,4 @@ prec.left(precedence, seq(

update_expression: $ => prec.left(PREC.INC, choice(
update_expression: $ => prec.left(PREC.UNARY, choice(
// Post (in|de)crement is evaluated before pre (in|de)crement
seq($.expression, '++'),

@@ -289,3 +365,4 @@ seq($.expression, '--'),

$.method_reference,
$.array_creation_expression
$.array_creation_expression,
$.template_expression
),

@@ -295,2 +372,3 @@

'new',
repeat($._annotation),
field('type', $._simple_type),

@@ -313,4 +391,6 @@ choice(

class_literal: $ => seq($._unannotated_type, '.', 'class'),
condition: $ => seq('(', $.expression, ')'),
class_literal: $ => prec.dynamic(PREC.CLASS_LITERAL, seq($._unannotated_type, '.', 'class')),
object_creation_expression: $ => choice(

@@ -323,3 +403,10 @@ $._unqualified_object_creation_expression,

'new',
field('type_arguments', optional($.type_arguments)),
choice(
seq(
repeat($._annotation),
field('type_arguments', $.type_arguments),
repeat($._annotation),
),
repeat($._annotation),
),
field('type', $._simple_type),

@@ -340,2 +427,8 @@ field('arguments', $.argument_list),

template_expression: $ => seq(
field('template_processor', $.primary_expression),
'.',
field('template_argument', $.string_literal)
),
array_access: $ => seq(

@@ -395,2 +488,57 @@ field('array', $.primary_expression),

switch_expression: $ => seq(
'switch',
field('condition', $.parenthesized_expression),
field('body', $.switch_block)
),
switch_block: $ => seq(
'{',
choice(
repeat($.switch_block_statement_group),
repeat($.switch_rule)
),
'}'
),
switch_block_statement_group: $ => prec.left(seq(
repeat1(seq($.switch_label, ':')),
repeat($.statement),
)),
switch_rule: $ => seq(
$.switch_label,
'->',
choice($.expression_statement, $.throw_statement, $.block)
),
switch_label: $ => choice(
seq('case',
choice(
$.pattern,
commaSep1($.expression)
),
optional($.guard)
),
'default'
),
pattern: $ => choice(
$.type_pattern,
$.record_pattern,
),
type_pattern: $ => seq($._unannotated_type, choice($.identifier, $._reserved_identifier)),
record_pattern: $ => seq(choice($.identifier, $._reserved_identifier, $.generic_type), $.record_pattern_body),
record_pattern_body: $ => seq('(', commaSep(choice($.record_pattern_component, $.record_pattern)), ')'),
record_pattern_component: $ => choice(
$.underscore_pattern,
seq(
$._unannotated_type,
choice($.identifier, $._reserved_identifier)
)),
underscore_pattern: $ => '_',
guard: $ => seq('when', $.expression),
// Statements

@@ -409,3 +557,2 @@

$.assert_statement,
$.switch_statement,
$.do_statement,

@@ -415,2 +562,4 @@ $.break_statement,

$.return_statement,
$.yield_statement,
$.switch_expression, // switch statements and expressions are identical
$.synchronized_statement,

@@ -441,19 +590,2 @@ $.local_variable_declaration,

switch_statement: $ => seq(
'switch',
field('condition', $.parenthesized_expression),
field('body', $.switch_block)
),
switch_block: $ => seq(
'{',
repeat(choice($.switch_label, $.statement)),
'}'
),
switch_label: $ => choice(
seq('case', $.expression, ':'),
seq('default', ':')
),
do_statement: $ => seq(

@@ -477,2 +609,8 @@ 'do',

yield_statement: $ => seq(
'yield',
$.expression,
';'
),
synchronized_statement: $ => seq(

@@ -539,3 +677,3 @@ 'synchronized',

'if',
field('condition', $.parenthesized_expression),
field('condition', $.condition),
field('consequence', $.statement),

@@ -547,3 +685,3 @@ optional(seq('else', field('alternative', $.statement)))

'while',
field('condition', $.parenthesized_expression),
field('condition', $.condition),
field('body', $.statement)

@@ -611,3 +749,3 @@ ),

_element_value: $ => prec(1, choice(
_element_value: $ => prec(PREC.ELEMENT_VAL, choice(
$.expression,

@@ -627,3 +765,3 @@ $.element_value_array_initializer,

declaration: $ => prec(1, choice(
declaration: $ => prec(PREC.DECL, choice(
$.module_declaration,

@@ -633,2 +771,3 @@ $.package_declaration,

$.class_declaration,
$.record_declaration,
$.interface_declaration,

@@ -653,10 +792,17 @@ $.annotation_type_declaration,

module_directive: $ => seq(choice(
seq('requires', repeat($.requires_modifier), $._name),
seq('exports', $._name, optional('to'), optional($._name), repeat(seq(',', $._name))),
seq('opens', $._name, optional('to'), optional($._name), repeat(seq(',', $._name))),
seq('uses', $._name),
seq('provides', $._name, 'with', $._name, repeat(seq(',', $._name)))
), ';'),
module_directive: $ => choice(
$.requires_module_directive,
$.exports_module_directive,
$.opens_module_directive,
$.uses_module_directive,
$.provides_module_directive
),
requires_module_directive: $ => seq(
'requires',
repeat(field('modifiers', $.requires_modifier)),
field('module', $._name),
';'
),
requires_modifier: $ => choice(

@@ -667,2 +813,39 @@ 'transitive',

exports_module_directive: $ => seq(
'exports',
field('package', $._name),
optional(seq(
'to',
field('modules', $._name),
repeat(seq(',', field('modules', $._name)))
)),
';'
),
opens_module_directive: $ => seq(
'opens',
field('package', $._name),
optional(seq(
'to',
field('modules', $._name),
repeat(seq(',', field('modules', $._name)))
)),
';'
),
uses_module_directive: $ => seq(
'uses',
field('type', $._name),
';'
),
provides_module_directive: $ => seq(
'provides',
field('provided', $._name),
'with',
$._name,
repeat(seq(',', (field('provider', $._name)))),
';'
),
package_declaration: $ => seq(

@@ -720,2 +903,3 @@ repeat($._annotation),

optional(field('interfaces', $.super_interfaces)),
optional(field('permits', $.permits)),
field('body', $.class_body)

@@ -737,3 +921,5 @@ ),

'transient',
'volatile'
'volatile',
'sealed',
'non-sealed',
)),

@@ -747,3 +933,3 @@

repeat($._annotation),
$.identifier,
alias($.identifier, $.type_identifier),
optional($.type_bound)

@@ -761,6 +947,6 @@ ),

'implements',
$.interface_type_list
$.type_list
),
interface_type_list: $ => seq(
type_list: $ => seq(
$._type,

@@ -770,2 +956,7 @@ repeat(seq(',', $._type))

permits: $ => seq(
'permits',
$.type_list
),
class_body: $ => seq(

@@ -779,3 +970,5 @@ '{',

$.field_declaration,
$.record_declaration,
$.method_declaration,
$.compact_constructor_declaration, // For records.
$.class_declaration,

@@ -852,2 +1045,12 @@ $.interface_declaration,

record_declaration: $ => seq(
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)
),
annotation_type_declaration: $ => seq(

@@ -861,3 +1064,4 @@ optional($.modifiers),

annotation_type_body: $ => seq(
'{', repeat(choice(
'{',
repeat(choice(
$.annotation_type_element_declaration,

@@ -867,3 +1071,5 @@ $.constant_declaration,

$.interface_declaration,
$.annotation_type_declaration
$.enum_declaration,
$.annotation_type_declaration,
';',
)),

@@ -876,3 +1082,3 @@ '}'

field('type', $._unannotated_type),
field('name', $.identifier),
field('name', choice($.identifier, $._reserved_identifier)),
'(', ')',

@@ -895,2 +1101,3 @@ field('dimensions', optional($.dimensions)),

optional($.extends_interfaces),
optional(field('permits', $.permits)),
field('body', $.interface_body)

@@ -901,3 +1108,3 @@ ),

'extends',
$.interface_type_list
$.type_list
),

@@ -913,2 +1120,3 @@

$.interface_declaration,
$.record_declaration,
$.annotation_type_declaration,

@@ -937,3 +1145,3 @@ ';'

_variable_declarator_id: $ => seq(
field('name', choice($.identifier, $._reserved_identifier)),
field('name', choice($.identifier, $._reserved_identifier, $.underscore_pattern)),
field('dimensions', optional($.dimensions))

@@ -992,3 +1200,3 @@ ),

generic_type: $ => prec.dynamic(10, seq(
generic_type: $ => prec.dynamic(PREC.GENERIC, seq(
choice(

@@ -1041,4 +1249,9 @@ alias($.identifier, $.type_identifier),

'(',
optional($.receiver_parameter),
commaSep(choice($.formal_parameter, $.spread_parameter)),
choice(
$.receiver_parameter,
seq(
optional(seq($.receiver_parameter, ',')),
commaSep(choice($.formal_parameter, $.spread_parameter)),
),
),
')'

@@ -1056,3 +1269,3 @@ ),

$._unannotated_type,
optional(seq($.identifier, '.')),
repeat(seq($.identifier, '.')),
$.this

@@ -1085,7 +1298,20 @@ ),

_reserved_identifier: $ => alias(choice(
'open',
'module'
), $.identifier),
compact_constructor_declaration: $ => seq(
optional($.modifiers),
field('name', $.identifier),
field('body', $.block)
),
_reserved_identifier: $ => prec(-3, alias(
choice(
'open',
'module',
'record',
'with',
'yield',
'sealed',
),
$.identifier,
)),
this: $ => 'this',

@@ -1096,7 +1322,13 @@

// https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-IdentifierChars
identifier: $ => /[A-Za-z_$][A-Za-z0-9_$]*/,
identifier: $ => /[\p{L}_$][\p{L}\p{Nd}\u00A2_$]*/,
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(prec(PREC.COMMENT, choice(
seq('//', /.*/),
comment: $ => choice(
$.line_comment,
$.block_comment,
),
line_comment: $ => token(prec(PREC.COMMENT, seq('//', /[^\n]*/))),
block_comment: $ => token(prec(PREC.COMMENT,
seq(

@@ -1107,7 +1339,7 @@ '/*',

)
))),
)),
}
});
function sep1 (rule, separator) {
function sep1(rule, separator) {
return seq(rule, repeat(seq(separator, rule)));

@@ -1114,0 +1346,0 @@ }

{
"name": "tree-sitter-java",
"version": "0.19.1",
"version": "0.20.2",
"description": "Java grammar for tree-sitter",

@@ -20,6 +20,6 @@ "main": "bindings/node",

"devDependencies": {
"tree-sitter-cli": "^0.19.2"
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"build": "tree-sitter generate && node-gyp rebuild",
"test": "tree-sitter test && script/parse-examples",

@@ -26,0 +26,0 @@ "test-windows": "tree-sitter test",

tree-sitter-java
================
[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-java.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-java)
[![Build status](https://ci.appveyor.com/api/projects/status/keg0ldsqf19ogm4a/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-java/branch/master)
[![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).

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 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 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