Skip to content

Commit b97fadf

Browse files
committed
Update versions and requirements
1 parent 868620e commit b97fadf

24 files changed

+136501
-135366
lines changed

.editorconfig

+39
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include = [
2020
path = "bindings/rust/lib.rs"
2121

2222
[dependencies]
23-
tree-sitter = ">= 0.19, < 0.21"
23+
tree-sitter = ">=0.21.0"
2424

2525
[build-dependencies]
2626
cc = "1.0"

binding.gyp

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
"targets": [
33
{
44
"target_name": "tree_sitter_elixir_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",
12-
"src/scanner.c"
14+
# NOTE: if your language has an external scanner, add it here.
1315
],
1416
"cflags_c": [
15-
"-std=c99",
16-
]
17+
"-std=c11",
18+
],
1719
}
1820
]
1921
}

bindings/c/tree-sitter-elixir.pc.in

+11
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-elixir
6+
Description: Elixir grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-elixir
11+
Cflags: -I${includedir}

bindings/go/binding.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tree_sitter_elixir
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+
import "C"
7+
8+
import "unsafe"
9+
10+
// Get the tree-sitter Language for this grammar.
11+
func Language() unsafe.Pointer {
12+
return unsafe.Pointer(C.tree_sitter_elixir())
13+
}

bindings/go/binding_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package tree_sitter_elixir_test
2+
3+
import (
4+
"testing"
5+
6+
tree_sitter "github.com/smacker/go-tree-sitter"
7+
"github.com/tree-sitter/tree-sitter-elixir"
8+
)
9+
10+
func TestCanLoadGrammar(t *testing.T) {
11+
language := tree_sitter.NewLanguage(tree_sitter_elixir.Language())
12+
if language == nil {
13+
t.Errorf("Error loading Elixir grammar")
14+
}
15+
}

bindings/go/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/tree-sitter/tree-sitter-elixir
2+
3+
go 1.22
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8

bindings/node/binding.cc

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
#include "tree_sitter/parser.h"
2-
#include <node.h>
3-
#include "nan.h"
1+
#include <napi.h>
42

5-
using namespace v8;
3+
typedef struct TSLanguage TSLanguage;
64

7-
extern "C" TSLanguage * tree_sitter_elixir();
5+
extern "C" TSLanguage *tree_sitter_elixir();
86

9-
namespace {
7+
// "tree-sitter", "language" hashed with BLAKE2
8+
const napi_type_tag LANGUAGE_TYPE_TAG = {
9+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
10+
};
1011

11-
NAN_METHOD(New) {}
12-
13-
void Init(Local<Object> exports, Local<Object> module) {
14-
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15-
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
17-
18-
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19-
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
20-
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_elixir());
21-
22-
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("elixir").ToLocalChecked());
23-
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
12+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
13+
exports["name"] = Napi::String::New(env, "elixir");
14+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_elixir());
15+
language.TypeTag(&LANGUAGE_TYPE_TAG);
16+
exports["language"] = language;
17+
return exports;
2418
}
2519

26-
NODE_MODULE(tree_sitter_elixir_binding, Init)
27-
28-
} // namespace
20+
NODE_API_MODULE(tree_sitter_elixir_binding, Init)

bindings/node/index.d.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
type BaseNode = {
2+
type: string;
3+
named: boolean;
4+
};
5+
6+
type ChildNode = {
7+
multiple: boolean;
8+
required: boolean;
9+
types: BaseNode[];
10+
};
11+
12+
type NodeInfo =
13+
| (BaseNode & {
14+
subtypes: BaseNode[];
15+
})
16+
| (BaseNode & {
17+
fields: { [name: string]: ChildNode };
18+
children: ChildNode[];
19+
});
20+
21+
type Language = {
22+
name: string;
23+
language: unknown;
24+
nodeTypeInfo: NodeInfo[];
25+
};
26+
27+
declare const language: Language;
28+
export = language;

bindings/node/index.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
try {
2-
module.exports = require("../../build/Release/tree_sitter_elixir_binding");
3-
} catch (error1) {
4-
if (error1.code !== 'MODULE_NOT_FOUND') {
5-
throw error1;
6-
}
7-
try {
8-
module.exports = require("../../build/Debug/tree_sitter_elixir_binding");
9-
} catch (error2) {
10-
if (error2.code !== 'MODULE_NOT_FOUND') {
11-
throw error2;
12-
}
13-
throw error1
14-
}
15-
}
1+
const root = require("path").join(__dirname, "..", "..");
2+
3+
module.exports = require("node-gyp-build")(root);
164

175
try {
186
module.exports.nodeTypeInfo = require("../../src/node-types.json");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Elixir grammar for tree-sitter"
2+
3+
from ._binding import language
4+
5+
__all__ = ["language"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def language() -> int: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <Python.h>
2+
3+
typedef struct TSLanguage TSLanguage;
4+
5+
TSLanguage *tree_sitter_elixir(void);
6+
7+
static PyObject* _binding_language(PyObject *self, PyObject *args) {
8+
return PyLong_FromVoidPtr(tree_sitter_elixir());
9+
}
10+
11+
static PyMethodDef methods[] = {
12+
{"language", _binding_language, METH_NOARGS,
13+
"Get the tree-sitter language for this grammar."},
14+
{NULL, NULL, 0, NULL}
15+
};
16+
17+
static struct PyModuleDef module = {
18+
.m_base = PyModuleDef_HEAD_INIT,
19+
.m_name = "_binding",
20+
.m_doc = NULL,
21+
.m_size = -1,
22+
.m_methods = methods
23+
};
24+
25+
PyMODINIT_FUNC PyInit__binding(void) {
26+
return PyModule_Create(&module);
27+
}

bindings/python/tree_sitter_elixir/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)