forked from tree-sitter/tree-sitter-scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tree-sitter#400 from tree-sitter/generation
chore: generate and sync latest changes
- Loading branch information
Showing
17 changed files
with
4,762 additions
and
12,484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
VERSION := 0.0.1 | ||
|
||
LANGUAGE_NAME := tree-sitter-scala | ||
|
||
# repository | ||
SRC_DIR := src | ||
|
||
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null) | ||
|
||
ifeq ($(PARSER_URL),) | ||
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL)) | ||
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) | ||
PARSER_URL := $(subst :,/,$(PARSER_URL)) | ||
PARSER_URL := $(subst git@,https://,$(PARSER_URL)) | ||
endif | ||
endif | ||
|
||
TS ?= tree-sitter | ||
|
||
# ABI versioning | ||
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) | ||
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) | ||
|
||
# install directory layout | ||
PREFIX ?= /usr/local | ||
INCLUDEDIR ?= $(PREFIX)/include | ||
LIBDIR ?= $(PREFIX)/lib | ||
PCLIBDIR ?= $(LIBDIR)/pkgconfig | ||
|
||
# source/object files | ||
PARSER := $(SRC_DIR)/parser.c | ||
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) | ||
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) | ||
|
||
# flags | ||
ARFLAGS ?= rcs | ||
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC | ||
|
||
# OS-specific bits | ||
ifeq ($(OS),Windows_NT) | ||
$(error "Windows is not supported") | ||
else ifeq ($(shell uname),Darwin) | ||
SOEXT = dylib | ||
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib | ||
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib | ||
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, | ||
ifneq ($(ADDITIONAL_LIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), | ||
endif | ||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_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 ($(ADDITIONAL_LIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) | ||
endif | ||
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) | ||
endif | ||
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) | ||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig | ||
endif | ||
|
||
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc | ||
|
||
lib$(LANGUAGE_NAME).a: $(OBJS) | ||
$(AR) $(ARFLAGS) $@ $^ | ||
|
||
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) | ||
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ | ||
ifneq ($(STRIP),) | ||
$(STRIP) $@ | ||
endif | ||
|
||
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in | ||
sed -e 's|@URL@|$(PARSER_URL)|' \ | ||
-e 's|@VERSION@|$(VERSION)|' \ | ||
-e 's|@LIBDIR@|$(LIBDIR)|' \ | ||
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ | ||
-e 's|@REQUIRES@|$(REQUIRES)|' \ | ||
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \ | ||
-e 's|=$(PREFIX)|=$${prefix}|' \ | ||
-e 's|@PREFIX@|$(PREFIX)|' $< > $@ | ||
|
||
$(PARSER): $(SRC_DIR)/grammar.json | ||
$(TS) generate --no-bindings $^ | ||
|
||
install: all | ||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' | ||
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h | ||
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc | ||
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a | ||
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) | ||
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) | ||
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) | ||
|
||
uninstall: | ||
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ | ||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ | ||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ | ||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ | ||
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ | ||
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc | ||
|
||
clean: | ||
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) | ||
|
||
test: | ||
$(TS) test | ||
|
||
.PHONY: all install uninstall clean test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TREE_SITTER_SCALA_H_ | ||
#define TREE_SITTER_SCALA_H_ | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
const TSLanguage *tree_sitter_scala(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TREE_SITTER_SCALA_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix=@PREFIX@ | ||
libdir=@LIBDIR@ | ||
includedir=@INCLUDEDIR@ | ||
|
||
Name: tree-sitter-scala | ||
Description: Scala grammar for tree-sitter | ||
URL: @URL@ | ||
Version: @VERSION@ | ||
Requires: @REQUIRES@ | ||
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-scala | ||
Cflags: -I${includedir} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tree_sitter_scala | ||
|
||
// #cgo CFLAGS: -std=c11 -fPIC | ||
// #include "../../src/parser.c" | ||
// // NOTE: if your language has an external scanner, add it here. | ||
import "C" | ||
|
||
import "unsafe" | ||
|
||
// Get the tree-sitter Language for this grammar. | ||
func Language() unsafe.Pointer { | ||
return unsafe.Pointer(C.tree_sitter_scala()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tree_sitter_scala_test | ||
|
||
import ( | ||
"testing" | ||
|
||
tree_sitter "github.com/smacker/go-tree-sitter" | ||
"github.com/tree-sitter/tree-sitter-scala" | ||
) | ||
|
||
func TestCanLoadGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_scala.Language()) | ||
if language == nil { | ||
t.Errorf("Error loading Scala grammar") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/tree-sitter/tree-sitter-scala | ||
|
||
go 1.22 | ||
|
||
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"Scala grammar for tree-sitter" | ||
|
||
from ._binding import language | ||
|
||
__all__ = ["language"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def language() -> int: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <Python.h> | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
TSLanguage *tree_sitter_scala(void); | ||
|
||
static PyObject* _binding_language(PyObject *self, PyObject *args) { | ||
return PyLong_FromVoidPtr(tree_sitter_scala()); | ||
} | ||
|
||
static PyMethodDef methods[] = { | ||
{"language", _binding_language, METH_NOARGS, | ||
"Get the tree-sitter language for this grammar."}, | ||
{NULL, NULL, 0, NULL} | ||
}; | ||
|
||
static struct PyModuleDef module = { | ||
.m_base = PyModuleDef_HEAD_INIT, | ||
.m_name = "_binding", | ||
.m_doc = NULL, | ||
.m_size = -1, | ||
.m_methods = methods | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit__binding(void) { | ||
return PyModule_Create(&module); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[build-system] | ||
requires = ["setuptools>=42", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "tree-sitter-scala" | ||
description = "Scala grammar for tree-sitter" | ||
version = "0.0.1" | ||
keywords = ["incremental", "parsing", "tree-sitter", "scala"] | ||
classifiers = [ | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Topic :: Software Development :: Compilers", | ||
"Topic :: Text Processing :: Linguistic", | ||
"Typing :: Typed" | ||
] | ||
requires-python = ">=3.8" | ||
license.text = "MIT" | ||
readme = "README.md" | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/tree-sitter/tree-sitter-scala" | ||
|
||
[project.optional-dependencies] | ||
core = ["tree-sitter~=0.21"] | ||
|
||
[tool.cibuildwheel] | ||
build = "cp38-*" | ||
build-frontend = "build" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from os.path import isdir, join | ||
from platform import system | ||
|
||
from setuptools import Extension, find_packages, setup | ||
from setuptools.command.build import build | ||
from wheel.bdist_wheel import bdist_wheel | ||
|
||
|
||
class Build(build): | ||
def run(self): | ||
if isdir("queries"): | ||
dest = join(self.build_lib, "tree_sitter_scala", "queries") | ||
self.copy_tree("queries", dest) | ||
super().run() | ||
|
||
|
||
class BdistWheel(bdist_wheel): | ||
def get_tag(self): | ||
python, abi, platform = super().get_tag() | ||
if python.startswith("cp"): | ||
python, abi = "cp38", "abi3" | ||
return python, abi, platform | ||
|
||
|
||
setup( | ||
packages=find_packages("bindings/python"), | ||
package_dir={"": "bindings/python"}, | ||
package_data={ | ||
"tree_sitter_scala": ["*.pyi", "py.typed"], | ||
"tree_sitter_scala.queries": ["*.scm"], | ||
}, | ||
ext_package="tree_sitter_scala", | ||
ext_modules=[ | ||
Extension( | ||
name="_binding", | ||
sources=[ | ||
"bindings/python/tree_sitter_scala/binding.c", | ||
"src/parser.c", | ||
# NOTE: if your language uses an external scanner, add it here. | ||
], | ||
extra_compile_args=[ | ||
"-std=c11", | ||
] if system() != "Windows" else [ | ||
"/std:c11", | ||
"/utf-8", | ||
], | ||
define_macros=[ | ||
("Py_LIMITED_API", "0x03080000"), | ||
("PY_SSIZE_T_CLEAN", None) | ||
], | ||
include_dirs=["src"], | ||
py_limited_api=True, | ||
) | ||
], | ||
cmdclass={ | ||
"build": Build, | ||
"bdist_wheel": BdistWheel | ||
}, | ||
zip_safe=False | ||
) |
Oops, something went wrong.