Skip to content

Commit 5bce09b

Browse files
authored
Merge pull request #400 from tree-sitter/generation
chore: generate and sync latest changes
2 parents 3080c54 + 9b739be commit 5bce09b

File tree

17 files changed

+4762
-12484
lines changed

17 files changed

+4762
-12484
lines changed

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
VERSION := 0.0.1
2+
3+
LANGUAGE_NAME := tree-sitter-scala
4+
5+
# repository
6+
SRC_DIR := src
7+
8+
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
9+
10+
ifeq ($(PARSER_URL),)
11+
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
12+
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
13+
PARSER_URL := $(subst :,/,$(PARSER_URL))
14+
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
15+
endif
16+
endif
17+
18+
TS ?= tree-sitter
19+
20+
# ABI versioning
21+
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
22+
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
23+
24+
# install directory layout
25+
PREFIX ?= /usr/local
26+
INCLUDEDIR ?= $(PREFIX)/include
27+
LIBDIR ?= $(PREFIX)/lib
28+
PCLIBDIR ?= $(LIBDIR)/pkgconfig
29+
30+
# source/object files
31+
PARSER := $(SRC_DIR)/parser.c
32+
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c))
33+
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS))
34+
35+
# flags
36+
ARFLAGS ?= rcs
37+
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
38+
39+
# OS-specific bits
40+
ifeq ($(OS),Windows_NT)
41+
$(error "Windows is not supported")
42+
else ifeq ($(shell uname),Darwin)
43+
SOEXT = dylib
44+
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
45+
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
46+
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
47+
ifneq ($(ADDITIONAL_LIBS),)
48+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
49+
endif
50+
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
51+
else
52+
SOEXT = so
53+
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
54+
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
55+
LINKSHARED := $(LINKSHARED)-shared -Wl,
56+
ifneq ($(ADDITIONAL_LIBS),)
57+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
58+
endif
59+
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
60+
endif
61+
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
62+
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
63+
endif
64+
65+
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
66+
67+
lib$(LANGUAGE_NAME).a: $(OBJS)
68+
$(AR) $(ARFLAGS) $@ $^
69+
70+
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
71+
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
72+
ifneq ($(STRIP),)
73+
$(STRIP) $@
74+
endif
75+
76+
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
77+
sed -e 's|@URL@|$(PARSER_URL)|' \
78+
-e 's|@VERSION@|$(VERSION)|' \
79+
-e 's|@LIBDIR@|$(LIBDIR)|' \
80+
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
81+
-e 's|@REQUIRES@|$(REQUIRES)|' \
82+
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
83+
-e 's|=$(PREFIX)|=$${prefix}|' \
84+
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
85+
86+
$(PARSER): $(SRC_DIR)/grammar.json
87+
$(TS) generate --no-bindings $^
88+
89+
install: all
90+
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
91+
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
92+
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
93+
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
94+
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
95+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
96+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
97+
98+
uninstall:
99+
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
100+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
101+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
102+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
103+
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
104+
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
105+
106+
clean:
107+
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
108+
109+
test:
110+
$(TS) test
111+
112+
.PHONY: all install uninstall clean test

bindings/c/tree-sitter-scala.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TREE_SITTER_SCALA_H_
2+
#define TREE_SITTER_SCALA_H_
3+
4+
typedef struct TSLanguage TSLanguage;
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
const TSLanguage *tree_sitter_scala(void);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif // TREE_SITTER_SCALA_H_

bindings/c/tree-sitter-scala.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@PREFIX@
2+
libdir=@LIBDIR@
3+
includedir=@INCLUDEDIR@
4+
5+
Name: tree-sitter-scala
6+
Description: Scala grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-scala
11+
Cflags: -I${includedir}

bindings/go/binding.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tree_sitter_scala
2+
3+
// #cgo CFLAGS: -std=c11 -fPIC
4+
// #include "../../src/parser.c"
5+
// // NOTE: if your language has an external scanner, add it here.
6+
import "C"
7+
8+
import "unsafe"
9+
10+
// Get the tree-sitter Language for this grammar.
11+
func Language() unsafe.Pointer {
12+
return unsafe.Pointer(C.tree_sitter_scala())
13+
}

bindings/go/binding_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package tree_sitter_scala_test
2+
3+
import (
4+
"testing"
5+
6+
tree_sitter "github.com/smacker/go-tree-sitter"
7+
"github.com/tree-sitter/tree-sitter-scala"
8+
)
9+
10+
func TestCanLoadGrammar(t *testing.T) {
11+
language := tree_sitter.NewLanguage(tree_sitter_scala.Language())
12+
if language == nil {
13+
t.Errorf("Error loading Scala grammar")
14+
}
15+
}

bindings/go/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/tree-sitter/tree-sitter-scala
2+
3+
go 1.22
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Scala grammar for tree-sitter"
2+
3+
from ._binding import language
4+
5+
__all__ = ["language"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def language() -> int: ...
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <Python.h>
2+
3+
typedef struct TSLanguage TSLanguage;
4+
5+
TSLanguage *tree_sitter_scala(void);
6+
7+
static PyObject* _binding_language(PyObject *self, PyObject *args) {
8+
return PyLong_FromVoidPtr(tree_sitter_scala());
9+
}
10+
11+
static PyMethodDef methods[] = {
12+
{"language", _binding_language, METH_NOARGS,
13+
"Get the tree-sitter language for this grammar."},
14+
{NULL, NULL, 0, NULL}
15+
};
16+
17+
static struct PyModuleDef module = {
18+
.m_base = PyModuleDef_HEAD_INIT,
19+
.m_name = "_binding",
20+
.m_doc = NULL,
21+
.m_size = -1,
22+
.m_methods = methods
23+
};
24+
25+
PyMODINIT_FUNC PyInit__binding(void) {
26+
return PyModule_Create(&module);
27+
}

bindings/python/tree_sitter_scala/py.typed

Whitespace-only changes.

bindings/rust/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ fn main() {
66
.flag_if_supported("-Wno-unused-parameter")
77
.flag_if_supported("-Wno-unused-but-set-variable")
88
.flag_if_supported("-Wno-trigraphs");
9+
#[cfg(target_env = "msvc")]
10+
c_config.flag("-utf-8");
11+
912
let parser_path = src_dir.join("parser.c");
1013
let scanner_path = src_dir.join("scanner.c");
1114
c_config.file(&parser_path);

pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "tree-sitter-scala"
7+
description = "Scala grammar for tree-sitter"
8+
version = "0.0.1"
9+
keywords = ["incremental", "parsing", "tree-sitter", "scala"]
10+
classifiers = [
11+
"Intended Audience :: Developers",
12+
"License :: OSI Approved :: MIT License",
13+
"Topic :: Software Development :: Compilers",
14+
"Topic :: Text Processing :: Linguistic",
15+
"Typing :: Typed"
16+
]
17+
requires-python = ">=3.8"
18+
license.text = "MIT"
19+
readme = "README.md"
20+
21+
[project.urls]
22+
Homepage = "https://github.com/tree-sitter/tree-sitter-scala"
23+
24+
[project.optional-dependencies]
25+
core = ["tree-sitter~=0.21"]
26+
27+
[tool.cibuildwheel]
28+
build = "cp38-*"
29+
build-frontend = "build"

setup.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from os.path import isdir, join
2+
from platform import system
3+
4+
from setuptools import Extension, find_packages, setup
5+
from setuptools.command.build import build
6+
from wheel.bdist_wheel import bdist_wheel
7+
8+
9+
class Build(build):
10+
def run(self):
11+
if isdir("queries"):
12+
dest = join(self.build_lib, "tree_sitter_scala", "queries")
13+
self.copy_tree("queries", dest)
14+
super().run()
15+
16+
17+
class BdistWheel(bdist_wheel):
18+
def get_tag(self):
19+
python, abi, platform = super().get_tag()
20+
if python.startswith("cp"):
21+
python, abi = "cp38", "abi3"
22+
return python, abi, platform
23+
24+
25+
setup(
26+
packages=find_packages("bindings/python"),
27+
package_dir={"": "bindings/python"},
28+
package_data={
29+
"tree_sitter_scala": ["*.pyi", "py.typed"],
30+
"tree_sitter_scala.queries": ["*.scm"],
31+
},
32+
ext_package="tree_sitter_scala",
33+
ext_modules=[
34+
Extension(
35+
name="_binding",
36+
sources=[
37+
"bindings/python/tree_sitter_scala/binding.c",
38+
"src/parser.c",
39+
# NOTE: if your language uses an external scanner, add it here.
40+
],
41+
extra_compile_args=[
42+
"-std=c11",
43+
] if system() != "Windows" else [
44+
"/std:c11",
45+
"/utf-8",
46+
],
47+
define_macros=[
48+
("Py_LIMITED_API", "0x03080000"),
49+
("PY_SSIZE_T_CLEAN", None)
50+
],
51+
include_dirs=["src"],
52+
py_limited_api=True,
53+
)
54+
],
55+
cmdclass={
56+
"build": Build,
57+
"bdist_wheel": BdistWheel
58+
},
59+
zip_safe=False
60+
)

0 commit comments

Comments
 (0)