forked from Wilfred/difftastic
-
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.
* Update queries to 0.21.0 * Format remaining queries * Run codegen on 0.21.0 * Fix missing scanner include for Go bindings * Fix casing in `bindings/rust/lib.rs`
- Loading branch information
Showing
25 changed files
with
1,075 additions
and
412 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,10 @@ | ||
* text eol=lf | ||
|
||
src/*.json linguist-generated | ||
src/parser.c linguist-generated | ||
src/tree_sitter/* linguist-generated | ||
|
||
bindings/** linguist-generated | ||
binding.gyp linguist-generated | ||
setup.py linguist-generated | ||
Makefile linguist-generated |
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 |
---|---|---|
@@ -1,92 +1,94 @@ | ||
VERSION := 0.20.0 | ||
VERSION := 0.2.0 | ||
|
||
# Repository | ||
LANGUAGE_NAME := tree-sitter-purescript | ||
|
||
# repository | ||
SRC_DIR := src | ||
|
||
PARSER_REPO_URL ?= $(shell git -C $(SRC_DIR) remote get-url origin ) | ||
# the # in the sed pattern has to be escaped or it will be interpreted as a comment | ||
PARSER_NAME ?= $(shell basename $(PARSER_REPO_URL) | cut -d '-' -f3 | sed 's\#.git\#\#') | ||
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z ) | ||
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 | ||
|
||
# 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 | ||
|
||
# collect C++ sources, and link if necessary | ||
CPPSRC := $(wildcard $(SRC_DIR)/*.cc) | ||
# object files | ||
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) | ||
|
||
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 | ||
# flags | ||
ARFLAGS := rcs | ||
override CFLAGS += -I$(SRC_DIR) -std=c11 | ||
|
||
# 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), | ||
ifneq ($(ADDITIONAL_LIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), | ||
endif | ||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks | ||
else | ||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks | ||
else ifneq ($(filter $(shell uname),Linux FreeBSD NetBSD DragonFly),) | ||
SOEXT = so | ||
SOEXTVER_MAJOR = so.$(SONAME_MAJOR) | ||
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) | ||
LINKSHARED := $(LINKSHARED)-shared -Wl, | ||
ifneq ($(ADDITIONALLIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS) | ||
ifneq ($(ADDITIONAL_LIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) | ||
endif | ||
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(PARSER_NAME).so.$(SONAME_MAJOR) | ||
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) | ||
else ifeq ($(OS),Windows_NT) | ||
$(error "Windows is not supported") | ||
endif | ||
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly)) | ||
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) | ||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig | ||
endif | ||
|
||
# target to generate header is commented-out because the required tree-sitter.h.in file is not in the repo | ||
#all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) bindings/c/$(PARSER_NAME).h | ||
all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) | ||
|
||
libtree-sitter-$(PARSER_NAME).a: $(OBJ) | ||
$(AR) rcs $@ $^ | ||
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc | ||
|
||
$(SRC_DIR)/%.o: $(SRC_DIR)/%.c | ||
$(CC) -c $^ -o $@ | ||
|
||
lib$(LANGUAGE_NAME).a: $(OBJS) | ||
$(AR) $(ARFLAGS) $@ $^ | ||
|
||
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) | ||
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) | ||
$(CC) -fPIC $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ | ||
|
||
bindings/c/$(PARSER_NAME).h: | ||
sed -e 's|@UPPER_PARSERNAME@|$(UPPER_PARSER_NAME)|' \ | ||
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \ | ||
bindings/c/tree-sitter.h.in > $@ | ||
$(LANGUAGE_NAME).pc: | ||
sed > $@ bindings/c/$(LANGUAGE_NAME).pc.in \ | ||
-e 's|@URL@|$(PARSER_URL)|' \ | ||
-e 's|@VERSION@|$(VERSION)|' \ | ||
-e 's|@LIBDIR@|$(LIBDIR)|;' \ | ||
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|;' \ | ||
-e 's|=$(PREFIX)|=$${prefix}|' \ | ||
-e 's|@PREFIX@|$(PREFIX)|' \ | ||
-e 's|@REQUIRES@|$(REQUIRES)|' \ | ||
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' | ||
|
||
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 -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h | ||
install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc | ||
install -Dm755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a | ||
install -Dm755 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) | ||
|
||
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) bindings/c/$(PARSER_NAME).h | ||
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) | ||
|
||
.PHONY: all install clean |
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,25 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "TreeSitterPurescript", | ||
platforms: [.macOS(.v10_13), .iOS(.v11)], | ||
products: [ | ||
.library(name: "TreeSitterPurescript", targets: ["TreeSitterPurescript"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.target(name: "TreeSitterPurescript", | ||
path: ".", | ||
sources: [ | ||
"src/parser.c", | ||
// NOTE: if your language has an external scanner, add it here. | ||
"src/scanner.c" | ||
], | ||
resources: [ | ||
.copy("queries") | ||
], | ||
publicHeadersPath: "bindings/swift", | ||
cSettings: [.headerSearchPath("src")]) | ||
] | ||
) |
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_PURESCRIPT_H_ | ||
#define TREE_SITTER_PURESCRIPT_H_ | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern const TSLanguage *tree_sitter_purescript(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TREE_SITTER_PURESCRIPT_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-purescript | ||
Description: purescript grammar for tree-sitter | ||
URL: @URL@ | ||
Version: @VERSION@ | ||
Requires: @REQUIRES@ | ||
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-purescript | ||
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,14 @@ | ||
package tree_sitter_purescript | ||
|
||
// #cgo CFLAGS: -std=c11 -fPIC | ||
// #include "../../src/parser.c" | ||
// // NOTE: if your language has an external scanner, add it here. | ||
// #include "../../src/scanner.c" | ||
import "C" | ||
|
||
import "unsafe" | ||
|
||
// Get the tree-sitter Language for this grammar. | ||
func Language() unsafe.Pointer { | ||
return unsafe.Pointer(C.tree_sitter_purescript()) | ||
} |
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_purescript_test | ||
|
||
import ( | ||
"testing" | ||
|
||
tree_sitter "github.com/smacker/go-tree-sitter" | ||
"github.com/postsolar/tree-sitter-purescript" | ||
) | ||
|
||
func TestCanLoadGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_purescript.Language()) | ||
if language == nil { | ||
t.Errorf("Error loading Purescript 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/postsolar/tree-sitter-purescript | ||
|
||
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,3 @@ | ||
"Purescript grammar for tree-sitter" | ||
|
||
from ._binding import 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; | ||
|
||
extern const TSLanguage *tree_sitter_purescript(void); | ||
|
||
static PyObject* _binding_language(PyObject *self, PyObject *args) { | ||
return PyLong_FromVoidPtr((void *)tree_sitter_purescript()); | ||
} | ||
|
||
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
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_PURESCRIPT_H_ | ||
#define TREE_SITTER_PURESCRIPT_H_ | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern const TSLanguage *tree_sitter_purescript(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TREE_SITTER_PURESCRIPT_H_ |
Oops, something went wrong.