Skip to content

Commit 5b4a731

Browse files
authored
Update to 0.21.0 (Wilfred#20)
* 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`
1 parent 5c45dbb commit 5b4a731

File tree

25 files changed

+1075
-412
lines changed

25 files changed

+1075
-412
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text eol=lf
2+
3+
src/*.json linguist-generated
4+
src/parser.c linguist-generated
5+
src/tree_sitter/* linguist-generated
6+
7+
bindings/** linguist-generated
8+
binding.gyp linguist-generated
9+
setup.py linguist-generated
10+
Makefile linguist-generated

Makefile

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,94 @@
1-
VERSION := 0.20.0
1+
VERSION := 0.2.0
22

3-
# Repository
3+
LANGUAGE_NAME := tree-sitter-purescript
4+
5+
# repository
46
SRC_DIR := src
57

6-
PARSER_REPO_URL ?= $(shell git -C $(SRC_DIR) remote get-url origin )
7-
# the # in the sed pattern has to be escaped or it will be interpreted as a comment
8-
PARSER_NAME ?= $(shell basename $(PARSER_REPO_URL) | cut -d '-' -f3 | sed 's\#.git\#\#')
9-
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )
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+
# ABI versioning
19+
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
20+
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
1021

1122
# install directory layout
1223
PREFIX ?= /usr/local
1324
INCLUDEDIR ?= $(PREFIX)/include
1425
LIBDIR ?= $(PREFIX)/lib
1526
PCLIBDIR ?= $(LIBDIR)/pkgconfig
1627

17-
# collect C++ sources, and link if necessary
18-
CPPSRC := $(wildcard $(SRC_DIR)/*.cc)
28+
# object files
29+
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c))
1930

20-
ifeq (, $(CPPSRC))
21-
ADDITIONALLIBS :=
22-
else
23-
ADDITIONALLIBS := -lc++
24-
endif
25-
26-
# collect sources
27-
SRC := $(wildcard $(SRC_DIR)/*.c)
28-
SRC += $(CPPSRC)
29-
OBJ := $(addsuffix .o,$(basename $(SRC)))
30-
31-
# ABI versioning
32-
SONAME_MAJOR := 0
33-
SONAME_MINOR := 0
34-
35-
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
36-
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
37-
override CFLAGS += -std=gnu99 -fPIC
38-
override CXXFLAGS += -fPIC
31+
# flags
32+
ARFLAGS := rcs
33+
override CFLAGS += -I$(SRC_DIR) -std=c11
3934

4035
# OS-specific bits
4136
ifeq ($(shell uname),Darwin)
4237
SOEXT = dylib
4338
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
4439
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
4540
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
46-
ifneq ($(ADDITIONALLIBS),)
47-
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
41+
ifneq ($(ADDITIONAL_LIBS),)
42+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
4843
endif
49-
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
50-
else
44+
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
45+
else ifneq ($(filter $(shell uname),Linux FreeBSD NetBSD DragonFly),)
5146
SOEXT = so
5247
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
5348
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
5449
LINKSHARED := $(LINKSHARED)-shared -Wl,
55-
ifneq ($(ADDITIONALLIBS),)
56-
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS)
50+
ifneq ($(ADDITIONAL_LIBS),)
51+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
5752
endif
58-
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(PARSER_NAME).so.$(SONAME_MAJOR)
53+
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
54+
else ifeq ($(OS),Windows_NT)
55+
$(error "Windows is not supported")
5956
endif
60-
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
57+
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
6158
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
6259
endif
63-
64-
# target to generate header is commented-out because the required tree-sitter.h.in file is not in the repo
65-
#all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) bindings/c/$(PARSER_NAME).h
66-
all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
6760

68-
libtree-sitter-$(PARSER_NAME).a: $(OBJ)
69-
$(AR) rcs $@ $^
61+
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
62+
63+
$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
64+
$(CC) -c $^ -o $@
65+
66+
lib$(LANGUAGE_NAME).a: $(OBJS)
67+
$(AR) $(ARFLAGS) $@ $^
7068

71-
libtree-sitter-$(PARSER_NAME).$(SOEXTVER): $(OBJ)
72-
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
73-
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXT)
74-
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
69+
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
70+
$(CC) -fPIC $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
7571

76-
bindings/c/$(PARSER_NAME).h:
77-
sed -e 's|@UPPER_PARSERNAME@|$(UPPER_PARSER_NAME)|' \
78-
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
79-
bindings/c/tree-sitter.h.in > $@
72+
$(LANGUAGE_NAME).pc:
73+
sed > $@ bindings/c/$(LANGUAGE_NAME).pc.in \
74+
-e 's|@URL@|$(PARSER_URL)|' \
75+
-e 's|@VERSION@|$(VERSION)|' \
76+
-e 's|@LIBDIR@|$(LIBDIR)|;' \
77+
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|;' \
78+
-e 's|=$(PREFIX)|=$${prefix}|' \
79+
-e 's|@PREFIX@|$(PREFIX)|' \
80+
-e 's|@REQUIRES@|$(REQUIRES)|' \
81+
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|'
8082

8183
install: all
82-
install -d '$(DESTDIR)$(LIBDIR)'
83-
install -m755 libtree-sitter-$(PARSER_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).a
84-
install -m755 libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
85-
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
86-
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXT)
87-
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
84+
install -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
85+
install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
86+
install -Dm755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
87+
install -Dm755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
88+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
89+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
8890

8991
clean:
90-
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
92+
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
9193

9294
.PHONY: all install clean

Package.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// swift-tools-version:5.3
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "TreeSitterPurescript",
6+
platforms: [.macOS(.v10_13), .iOS(.v11)],
7+
products: [
8+
.library(name: "TreeSitterPurescript", targets: ["TreeSitterPurescript"]),
9+
],
10+
dependencies: [],
11+
targets: [
12+
.target(name: "TreeSitterPurescript",
13+
path: ".",
14+
sources: [
15+
"src/parser.c",
16+
// NOTE: if your language has an external scanner, add it here.
17+
"src/scanner.c"
18+
],
19+
resources: [
20+
.copy("queries")
21+
],
22+
publicHeadersPath: "bindings/swift",
23+
cSettings: [.headerSearchPath("src")])
24+
]
25+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TREE_SITTER_PURESCRIPT_H_
2+
#define TREE_SITTER_PURESCRIPT_H_
3+
4+
typedef struct TSLanguage TSLanguage;
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
extern const TSLanguage *tree_sitter_purescript(void);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif // TREE_SITTER_PURESCRIPT_H_
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-purescript
6+
Description: purescript grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-purescript
11+
Cflags: -I${includedir}

bindings/go/binding.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tree_sitter_purescript
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+
// #include "../../src/scanner.c"
7+
import "C"
8+
9+
import "unsafe"
10+
11+
// Get the tree-sitter Language for this grammar.
12+
func Language() unsafe.Pointer {
13+
return unsafe.Pointer(C.tree_sitter_purescript())
14+
}

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_purescript_test
2+
3+
import (
4+
"testing"
5+
6+
tree_sitter "github.com/smacker/go-tree-sitter"
7+
"github.com/postsolar/tree-sitter-purescript"
8+
)
9+
10+
func TestCanLoadGrammar(t *testing.T) {
11+
language := tree_sitter.NewLanguage(tree_sitter_purescript.Language())
12+
if language == nil {
13+
t.Errorf("Error loading Purescript 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/postsolar/tree-sitter-purescript
2+
3+
go 1.22
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Purescript grammar for tree-sitter"
2+
3+
from ._binding import language
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def language() -> int: ...

0 commit comments

Comments
 (0)