Skip to content

Commit b9b9e45

Browse files
Merge pull request #15 from SpontanCombust/dev
2 parents 31dae31 + c164b14 commit b9b9e45

32 files changed

+21375
-18904
lines changed

.editorconfig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{json,toml,yml,gyp}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.js]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.rs]
18+
indent_style = space
19+
indent_size = 4
20+
21+
[*.{c,cc,h}]
22+
indent_style = space
23+
indent_size = 4
24+
25+
[*.{py,pyi}]
26+
indent_style = space
27+
indent_size = 4
28+
29+
[*.swift]
30+
indent_style = space
31+
indent_size = 4
32+
33+
[*.go]
34+
indent_style = tab
35+
indent_size = 8
36+
37+
[Makefile]
38+
indent_style = tab
39+
indent_size = 8

Cargo.toml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
[package]
22
name = "tree-sitter-witcherscript"
33
description = "WitcherScript grammar for the tree-sitter parsing library"
4-
version = "0.10.1"
5-
keywords = ["incremental", "parsing", "witcherscript"]
4+
version = "0.12.0"
5+
readme = "README.md"
6+
keywords = ["incremental", "parsing", "tree-sitter", "witcherscript"]
67
categories = ["parsing", "text-editors"]
78
repository = "https://github.com/tree-sitter/tree-sitter-witcherscript"
89
edition = "2018"
910
license = "MIT"
11+
autoexamples = false
1012

1113
build = "bindings/rust/build.rs"
12-
include = [
13-
"bindings/rust/*",
14-
"grammar.js",
15-
"queries/*",
16-
"src/*",
17-
]
14+
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
1815

1916
[lib]
2017
path = "bindings/rust/lib.rs"
2118

2219
[dependencies]
23-
tree-sitter = "~0.20.10"
20+
tree-sitter = ">=0.22.6"
2421

2522
[build-dependencies]
26-
cc = "1.0"
23+
cc = "1.0.87"

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
VERSION := 0.12.0
2+
3+
LANGUAGE_NAME := tree-sitter-witcherscript
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

Package.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// swift-tools-version:5.3
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "TreeSitterWitcherscript",
6+
products: [
7+
.library(name: "TreeSitterWitcherscript", targets: ["TreeSitterWitcherscript"]),
8+
],
9+
dependencies: [],
10+
targets: [
11+
.target(name: "TreeSitterWitcherscript",
12+
path: ".",
13+
exclude: [
14+
"Cargo.toml",
15+
"Makefile",
16+
"binding.gyp",
17+
"bindings/c",
18+
"bindings/go",
19+
"bindings/node",
20+
"bindings/python",
21+
"bindings/rust",
22+
"prebuilds",
23+
"grammar.js",
24+
"package.json",
25+
"package-lock.json",
26+
"pyproject.toml",
27+
"setup.py",
28+
"test",
29+
"examples",
30+
".editorconfig",
31+
".github",
32+
".gitignore",
33+
".gitattributes",
34+
".gitmodules",
35+
],
36+
sources: [
37+
"src/parser.c",
38+
// NOTE: if your language has an external scanner, add it here.
39+
],
40+
resources: [
41+
.copy("queries")
42+
],
43+
publicHeadersPath: "bindings/swift",
44+
cSettings: [.headerSearchPath("src")])
45+
],
46+
cLanguageStandard: .c11
47+
)

binding.gyp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
"targets": [
33
{
44
"target_name": "tree_sitter_witcherscript_binding",
5+
"dependencies": [
6+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
7+
],
58
"include_dirs": [
6-
"<!(node -e \"require('nan')\")",
7-
"src"
9+
"src",
810
],
911
"sources": [
1012
"bindings/node/binding.cc",
1113
"src/parser.c",
14+
# NOTE: if your language has an external scanner, add it here.
1215
"src/scanner.c"
1316
],
14-
"cflags_c": [
15-
"-std=c99",
16-
]
17+
"conditions": [
18+
["OS!='win'", {
19+
"cflags_c": [
20+
"-std=c11",
21+
],
22+
}, { # OS == "win"
23+
"cflags_c": [
24+
"/std:c11",
25+
"/utf-8",
26+
],
27+
}],
28+
],
1729
}
1830
]
1931
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TREE_SITTER_WITCHERSCRIPT_H_
2+
#define TREE_SITTER_WITCHERSCRIPT_H_
3+
4+
typedef struct TSLanguage TSLanguage;
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
const TSLanguage *tree_sitter_witcherscript(void);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif // TREE_SITTER_WITCHERSCRIPT_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-witcherscript
6+
Description: Witcherscript grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-witcherscript
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_witcherscript
2+
3+
// #cgo CFLAGS: -std=c11 -fPIC
4+
// #include "../../src/parser.c"
5+
// #include "../../src/scanner.c"
6+
// // NOTE: if your language has an external scanner, add it here.
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_witcherscript())
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_witcherscript_test
2+
3+
import (
4+
"testing"
5+
6+
tree_sitter "github.com/smacker/go-tree-sitter"
7+
"github.com/tree-sitter/tree-sitter-witcherscript"
8+
)
9+
10+
func TestCanLoadGrammar(t *testing.T) {
11+
language := tree_sitter.NewLanguage(tree_sitter_witcherscript.Language())
12+
if language == nil {
13+
t.Errorf("Error loading Witcherscript 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-witcherscript
2+
3+
go 1.22
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8

0 commit comments

Comments
 (0)