Merge commit 'ac14b4b1884102839455d32543ab6d53ae089ab7'

pull/315/head
Wilfred Hughes 2022-07-10 23:05:53 +07:00
commit 3e0c108afe
14 changed files with 38243 additions and 34310 deletions

@ -9,3 +9,10 @@ test.java
/examples/guava
/examples/RxJava
/target/
*.a
*.dylib
*.so
*.o
bindings/c/*.h
bindings/c/tree-sitter-*.pc
.build/

@ -0,0 +1,114 @@
VERSION := 0.19.1
# Repository
SRC_DIR := src
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin )
ifeq (, $(PARSER_NAME))
PARSER_NAME := $(shell basename $(PARSER_REPO_URL))
PARSER_NAME := $(subst tree-sitter-,,$(PARSER_NAME))
PARSER_NAME := $(subst .git,,$(PARSER_NAME))
endif
ifeq (, $(PARSER_URL))
PARSER_URL := $(subst :,/,$(PARSER_REPO_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
PARSER_URL := $(subst .git,,$(PARSER_URL))
endif
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )
# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig
# collect C++ sources, and link if necessary
CPPSRC := $(wildcard $(SRC_DIR)/*.cc)
ifeq (, $(CPPSRC))
ADDITIONALLIBS :=
else
ADDITIONALLIBS := -lc++
endif
# collect sources
SRC := $(wildcard $(SRC_DIR)/*.c)
SRC += $(CPPSRC)
OBJ := $(addsuffix .o,$(basename $(SRC)))
# ABI versioning
SONAME_MAJOR := 0
SONAME_MINOR := 0
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
override CFLAGS += -std=gnu99 -fPIC
override CXXFLAGS += -fPIC
# OS-specific bits
ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(PARSER_NAME).so.$(SONAME_MAJOR)
endif
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif
all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc
libtree-sitter-$(PARSER_NAME).a: $(OBJ)
$(AR) rcs $@ $^
libtree-sitter-$(PARSER_NAME).$(SOEXTVER): $(OBJ)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXT)
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
bindings/c/$(PARSER_NAME).h:
sed -e 's|@UPPER_PARSERNAME@|$(UPPER_PARSER_NAME)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
bindings/c/tree-sitter.h.in > $@
bindings/c/tree-sitter-$(PARSER_NAME).pc:
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' \
-e 's|@ADDITIONALLIBS@|$(ADDITIONALLIBS)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
-e 's|@PARSERURL@|$(PARSER_URL)|' \
bindings/c/tree-sitter.pc.in > $@
install: all
install -d '$(DESTDIR)$(LIBDIR)'
install -m755 libtree-sitter-$(PARSER_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).a
install -m755 libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXT)
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
install -m644 bindings/c/$(PARSER_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/
install -d '$(DESTDIR)$(PCLIBDIR)'
install -m644 bindings/c/tree-sitter-$(PARSER_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/
clean:
rm -f $(OBJ) libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXT) libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR) libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
rm -f bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc
.PHONY: all install clean

@ -0,0 +1,36 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterJava",
products: [
.library(name: "TreeSitterJava", targets: ["TreeSitterJava"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterJava",
path: ".",
exclude: [
"binding.gyp",
"bindings",
"Cargo.toml",
"corpus",
"grammar.js",
"LICENSE",
"Makefile",
"package.json",
"README.md",
"script",
"src/grammar.json",
"src/node-types.json",
],
sources: [
"src/parser.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
]
)

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_@UPPER_PARSERNAME@_H_
#define TREE_SITTER_@UPPER_PARSERNAME@_H_
#include <tree_sitter/parser.h>
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_@PARSERNAME@();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_@UPPER_PARSERNAME@_H_

@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
additionallibs=@ADDITIONALLIBS@
Name: tree-sitter-@PARSERNAME@
Description: A tree-sitter grammar for the @PARSERNAME@ programming language.
URL: @PARSERURL@
Version: @VERSION@
Libs: -L${libdir} ${additionallibs} -ltree-sitter-@PARSERNAME@
Cflags: -I${includedir}

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_JAVA_H_
#define TREE_SITTER_JAVA_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_java();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_JAVA_H_

@ -763,6 +763,7 @@ module.exports = grammar({
optional(field('type_parameters', $.type_parameters)),
optional(field('superclass', $.superclass)),
optional(field('interfaces', $.super_interfaces)),
optional(field('permits', $.permits)),
field('body', $.class_body)
),
@ -779,7 +780,9 @@ module.exports = grammar({
'synchronized',
'native',
'transient',
'volatile'
'volatile',
'sealed',
'non-sealed',
)),
type_parameters: $ => seq(
@ -801,14 +804,19 @@ module.exports = grammar({
super_interfaces: $ => seq(
'implements',
$.interface_type_list
$.type_list
),
interface_type_list: $ => seq(
type_list: $ => seq(
$._type,
repeat(seq(',', $._type))
),
permits: $ => seq(
'permits',
$.type_list
),
class_body: $ => seq(
'{',
repeat($._class_body_declaration),
@ -937,12 +945,13 @@ module.exports = grammar({
field('name', $.identifier),
field('type_parameters', optional($.type_parameters)),
optional($.extends_interfaces),
optional(field('permits', $.permits)),
field('body', $.interface_body)
),
extends_interfaces: $ => seq(
'extends',
$.interface_type_list
$.type_list
),
interface_body: $ => seq(

@ -17,7 +17,7 @@
"nan": "^2.14.1"
},
"devDependencies": {
"tree-sitter-cli": "^0.19.3"
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"build": "tree-sitter generate && node-gyp rebuild",

@ -112,6 +112,7 @@
"module"
"native"
"new"
"non-sealed"
"open"
"opens"
"package"
@ -121,6 +122,7 @@
"public"
"requires"
"return"
"sealed"
"static"
"strictfp"
"switch"

@ -11,7 +11,7 @@
(interface_declaration
name: (identifier) @name) @definition.interface
(interface_type_list
(type_list
(type_identifier) @name) @reference.implementation
(object_creation_expression

@ -5066,6 +5066,22 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "permits",
"content": {
"type": "SYMBOL",
"name": "permits"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
@ -5132,6 +5148,14 @@
{
"type": "STRING",
"value": "volatile"
},
{
"type": "STRING",
"value": "sealed"
},
{
"type": "STRING",
"value": "non-sealed"
}
]
}
@ -5258,11 +5282,11 @@
},
{
"type": "SYMBOL",
"name": "interface_type_list"
"name": "type_list"
}
]
},
"interface_type_list": {
"type_list": {
"type": "SEQ",
"members": [
{
@ -5287,6 +5311,19 @@
}
]
},
"permits": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "permits"
},
{
"type": "SYMBOL",
"name": "type_list"
}
]
},
"class_body": {
"type": "SEQ",
"members": [
@ -5928,6 +5965,22 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "permits",
"content": {
"type": "SYMBOL",
"name": "permits"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "body",
@ -5947,7 +6000,7 @@
},
{
"type": "SYMBOL",
"name": "interface_type_list"
"name": "type_list"
}
]
},

@ -1158,6 +1158,16 @@
}
]
},
"permits": {
"multiple": false,
"required": false,
"types": [
{
"type": "permits",
"named": true
}
]
},
"superclass": {
"multiple": false,
"required": false,
@ -1804,7 +1814,7 @@
"required": true,
"types": [
{
"type": "interface_type_list",
"type": "type_list",
"named": true
}
]
@ -2216,6 +2226,16 @@
}
]
},
"permits": {
"multiple": false,
"required": false,
"types": [
{
"type": "permits",
"named": true
}
]
},
"type_parameters": {
"multiple": false,
"required": false,
@ -2242,21 +2262,6 @@
]
}
},
{
"type": "interface_type_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "_type",
"named": true
}
]
}
},
{
"type": "labeled_statement",
"named": true,
@ -2749,6 +2754,21 @@
]
}
},
{
"type": "permits",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "type_list",
"named": true
}
]
}
},
{
"type": "program",
"named": true,
@ -3126,7 +3146,7 @@
"required": true,
"types": [
{
"type": "interface_type_list",
"type": "type_list",
"named": true
}
]
@ -3449,6 +3469,21 @@
]
}
},
{
"type": "type_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "_type",
"named": true
}
]
}
},
{
"type": "type_parameter",
"named": true,
@ -4016,6 +4051,10 @@
"type": "new",
"named": false
},
{
"type": "non-sealed",
"named": false
},
{
"type": "null_literal",
"named": true
@ -4036,6 +4075,10 @@
"type": "package",
"named": false
},
{
"type": "permits",
"named": false
},
{
"type": "private",
"named": false
@ -4064,6 +4107,10 @@
"type": "return",
"named": false
},
{
"type": "sealed",
"named": false
},
{
"type": "short",
"named": false

File diff suppressed because it is too large Load Diff

@ -324,7 +324,7 @@ public class Dog implements ISpeak {
(program
(class_declaration
(modifiers) (identifier)
(super_interfaces (interface_type_list (type_identifier))) (class_body)))
(super_interfaces (type_list (type_identifier))) (class_body)))
============================
class declaration with body
@ -383,11 +383,11 @@ interface Bottom extends Left, Right {}
(program
(interface_declaration
(identifier)
(extends_interfaces (interface_type_list (type_identifier)))
(extends_interfaces (type_list (type_identifier)))
(interface_body))
(interface_declaration
(identifier)
(extends_interfaces (interface_type_list (type_identifier) (type_identifier))) (interface_body)))
(extends_interfaces (type_list (type_identifier) (type_identifier))) (interface_body)))
===========================================
interface with annotation type declaration
@ -668,3 +668,40 @@ class A$B {
(method_invocation
(identifier)
(argument_list))))))))
================
Sealed classes
================
sealed interface A permits B, C {
}
final class B implements A {}
non-sealed interface C extends A {}
---
(program
(interface_declaration
(modifiers)
(identifier)
(permits
(type_list
(type_identifier)
(type_identifier)))
(interface_body))
(class_declaration
(modifiers)
(identifier)
(super_interfaces
(type_list
(type_identifier)))
(class_body))
(interface_declaration
(modifiers)
(identifier)
(extends_interfaces
(type_list
(type_identifier)))
(interface_body)))