aboutsummaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-04-18 11:07:53 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-04-18 11:35:24 +0200
commit4b160d1b2119cd2007ea7a76d4baba56ad66b825 (patch)
treea6c5d491c8306304cc9ec112ffedcae4ff6bced3 /bindings
parent1f10ff9a6039a50e2f7be394fc22b1400832cf17 (diff)
Support comments… sortav1.2.0
Diffstat (limited to 'bindings')
-rw-r--r--bindings/c/tree-sitter-gsp.h16
-rw-r--r--bindings/c/tree-sitter-gsp.pc.in11
-rw-r--r--bindings/go/binding.go13
-rw-r--r--bindings/go/binding_test.go15
-rw-r--r--bindings/go/go.mod5
-rw-r--r--bindings/node/binding.cc36
-rw-r--r--bindings/node/index.d.ts28
-rw-r--r--bindings/node/index.js18
-rw-r--r--bindings/python/tree_sitter_gsp/__init__.py5
-rw-r--r--bindings/python/tree_sitter_gsp/__init__.pyi1
-rw-r--r--bindings/python/tree_sitter_gsp/binding.c27
-rw-r--r--bindings/python/tree_sitter_gsp/py.typed0
-rw-r--r--bindings/rust/build.rs3
-rw-r--r--bindings/swift/TreeSitterGsp/gsp.h16
14 files changed, 157 insertions, 37 deletions
diff --git a/bindings/c/tree-sitter-gsp.h b/bindings/c/tree-sitter-gsp.h
new file mode 100644
index 0000000..8f23915
--- /dev/null
+++ b/bindings/c/tree-sitter-gsp.h
@@ -0,0 +1,16 @@
+#ifndef TREE_SITTER_GSP_H_
+#define TREE_SITTER_GSP_H_
+
+typedef struct TSLanguage TSLanguage;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const TSLanguage *tree_sitter_gsp(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // TREE_SITTER_GSP_H_
diff --git a/bindings/c/tree-sitter-gsp.pc.in b/bindings/c/tree-sitter-gsp.pc.in
new file mode 100644
index 0000000..ba931d8
--- /dev/null
+++ b/bindings/c/tree-sitter-gsp.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: tree-sitter-gsp
+Description: Gsp grammar for tree-sitter
+URL: @URL@
+Version: @VERSION@
+Requires: @REQUIRES@
+Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-gsp
+Cflags: -I${includedir}
diff --git a/bindings/go/binding.go b/bindings/go/binding.go
new file mode 100644
index 0000000..353f400
--- /dev/null
+++ b/bindings/go/binding.go
@@ -0,0 +1,13 @@
+package tree_sitter_gsp
+
+// #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_gsp())
+}
diff --git a/bindings/go/binding_test.go b/bindings/go/binding_test.go
new file mode 100644
index 0000000..c4efff1
--- /dev/null
+++ b/bindings/go/binding_test.go
@@ -0,0 +1,15 @@
+package tree_sitter_gsp_test
+
+import (
+ "testing"
+
+ tree_sitter "github.com/smacker/go-tree-sitter"
+ "github.com/tree-sitter/tree-sitter-gsp"
+)
+
+func TestCanLoadGrammar(t *testing.T) {
+ language := tree_sitter.NewLanguage(tree_sitter_gsp.Language())
+ if language == nil {
+ t.Errorf("Error loading Gsp grammar")
+ }
+}
diff --git a/bindings/go/go.mod b/bindings/go/go.mod
new file mode 100644
index 0000000..38c34a6
--- /dev/null
+++ b/bindings/go/go.mod
@@ -0,0 +1,5 @@
+module github.com/tree-sitter/tree-sitter-gsp
+
+go 1.22
+
+require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc
index 81881bf..a813e24 100644
--- a/bindings/node/binding.cc
+++ b/bindings/node/binding.cc
@@ -1,28 +1,20 @@
-#include "tree_sitter/parser.h"
-#include <node.h>
-#include "nan.h"
+#include <napi.h>
-using namespace v8;
+typedef struct TSLanguage TSLanguage;
-extern "C" TSLanguage * tree_sitter_gsp();
+extern "C" TSLanguage *tree_sitter_gsp();
-namespace {
+// "tree-sitter", "language" hashed with BLAKE2
+const napi_type_tag LANGUAGE_TYPE_TAG = {
+ 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
+};
-NAN_METHOD(New) {}
-
-void Init(Local<Object> exports, Local<Object> module) {
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
- tpl->SetClassName(Nan::New("Language").ToLocalChecked());
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
-
- Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
- Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_gsp());
-
- Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("gsp").ToLocalChecked());
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
+Napi::Object Init(Napi::Env env, Napi::Object exports) {
+ exports["name"] = Napi::String::New(env, "gsp");
+ auto language = Napi::External<TSLanguage>::New(env, tree_sitter_gsp());
+ language.TypeTag(&LANGUAGE_TYPE_TAG);
+ exports["language"] = language;
+ return exports;
}
-NODE_MODULE(tree_sitter_gsp_binding, Init)
-
-} // namespace
+NODE_API_MODULE(tree_sitter_gsp_binding, Init)
diff --git a/bindings/node/index.d.ts b/bindings/node/index.d.ts
new file mode 100644
index 0000000..efe259e
--- /dev/null
+++ b/bindings/node/index.d.ts
@@ -0,0 +1,28 @@
+type BaseNode = {
+ type: string;
+ named: boolean;
+};
+
+type ChildNode = {
+ multiple: boolean;
+ required: boolean;
+ types: BaseNode[];
+};
+
+type NodeInfo =
+ | (BaseNode & {
+ subtypes: BaseNode[];
+ })
+ | (BaseNode & {
+ fields: { [name: string]: ChildNode };
+ children: ChildNode[];
+ });
+
+type Language = {
+ name: string;
+ language: unknown;
+ nodeTypeInfo: NodeInfo[];
+};
+
+declare const language: Language;
+export = language;
diff --git a/bindings/node/index.js b/bindings/node/index.js
index d0bc87e..6657bcf 100644
--- a/bindings/node/index.js
+++ b/bindings/node/index.js
@@ -1,18 +1,6 @@
-try {
- module.exports = require("../../build/Release/tree_sitter_gsp_binding");
-} catch (error1) {
- if (error1.code !== 'MODULE_NOT_FOUND') {
- throw error1;
- }
- try {
- module.exports = require("../../build/Debug/tree_sitter_gsp_binding");
- } catch (error2) {
- if (error2.code !== 'MODULE_NOT_FOUND') {
- throw error2;
- }
- throw error1
- }
-}
+const root = require("path").join(__dirname, "..", "..");
+
+module.exports = require("node-gyp-build")(root);
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
diff --git a/bindings/python/tree_sitter_gsp/__init__.py b/bindings/python/tree_sitter_gsp/__init__.py
new file mode 100644
index 0000000..a844d6d
--- /dev/null
+++ b/bindings/python/tree_sitter_gsp/__init__.py
@@ -0,0 +1,5 @@
+"Gsp grammar for tree-sitter"
+
+from ._binding import language
+
+__all__ = ["language"]
diff --git a/bindings/python/tree_sitter_gsp/__init__.pyi b/bindings/python/tree_sitter_gsp/__init__.pyi
new file mode 100644
index 0000000..5416666
--- /dev/null
+++ b/bindings/python/tree_sitter_gsp/__init__.pyi
@@ -0,0 +1 @@
+def language() -> int: ...
diff --git a/bindings/python/tree_sitter_gsp/binding.c b/bindings/python/tree_sitter_gsp/binding.c
new file mode 100644
index 0000000..569c1dc
--- /dev/null
+++ b/bindings/python/tree_sitter_gsp/binding.c
@@ -0,0 +1,27 @@
+#include <Python.h>
+
+typedef struct TSLanguage TSLanguage;
+
+TSLanguage *tree_sitter_gsp(void);
+
+static PyObject* _binding_language(PyObject *self, PyObject *args) {
+ return PyLong_FromVoidPtr(tree_sitter_gsp());
+}
+
+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);
+}
diff --git a/bindings/python/tree_sitter_gsp/py.typed b/bindings/python/tree_sitter_gsp/py.typed
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bindings/python/tree_sitter_gsp/py.typed
diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs
index c6061f0..4cc26f5 100644
--- a/bindings/rust/build.rs
+++ b/bindings/rust/build.rs
@@ -7,6 +7,9 @@ fn main() {
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
+ #[cfg(target_env = "msvc")]
+ c_config.flag("-utf-8");
+
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
diff --git a/bindings/swift/TreeSitterGsp/gsp.h b/bindings/swift/TreeSitterGsp/gsp.h
new file mode 100644
index 0000000..8f23915
--- /dev/null
+++ b/bindings/swift/TreeSitterGsp/gsp.h
@@ -0,0 +1,16 @@
+#ifndef TREE_SITTER_GSP_H_
+#define TREE_SITTER_GSP_H_
+
+typedef struct TSLanguage TSLanguage;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const TSLanguage *tree_sitter_gsp(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // TREE_SITTER_GSP_H_