Skip to content

Commit

Permalink
bump tree-sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed May 3, 2024
1 parent 95a4f00 commit 2c42e90
Show file tree
Hide file tree
Showing 22 changed files with 217,920 additions and 217,310 deletions.
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.rs]
indent_style = space
indent_size = 4

[*.{c,cc,h}]
indent_style = space
indent_size = 4

[*.{py,pyi}]
indent_style = space
indent_size = 4

[*.swift]
indent_style = space
indent_size = 4

[*.go]
indent_style = tab
indent_size = 8

[Makefile]
indent_style = tab
indent_size = 8
12 changes: 7 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
"targets": [
{
"target_name": "tree_sitter_haskell_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
"src",
],
"sources": [
"src/parser.c",
"bindings/node/binding.cc",
"src/parser.c",
"src/scanner.c",
"src/unicode.h",
],
"cflags_c": [
"-std=c99",
]
"-std=c11",
],
}
]
}
16 changes: 16 additions & 0 deletions bindings/c/tree-sitter-haskell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_HASKELL_H_
#define TREE_SITTER_HASKELL_H_

typedef struct TSLanguage TSLanguage;

#ifdef __cplusplus
extern "C" {
#endif

const TSLanguage *tree_sitter_haskell(void);

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_HASKELL_H_
11 changes: 11 additions & 0 deletions bindings/c/tree-sitter-haskell.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@

Name: tree-sitter-haskell
Description: Haskell grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-haskell
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions bindings/go/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tree_sitter_haskell

// #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_haskell())
}
15 changes: 15 additions & 0 deletions bindings/go/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tree_sitter_haskell_test

import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-haskell"
)

func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_haskell.Language())
if language == nil {
t.Errorf("Error loading Haskell grammar")
}
}
5 changes: 5 additions & 0 deletions bindings/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-haskell

go 1.22

require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
36 changes: 14 additions & 22 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -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_haskell();
extern "C" TSLanguage *tree_sitter_haskell();

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_haskell());

Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("haskell").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports["name"] = Napi::String::New(env, "haskell");
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_haskell());
language.TypeTag(&LANGUAGE_TYPE_TAG);
exports["language"] = language;
return exports;
}

NODE_MODULE(tree_sitter_haskell_binding, Init)

} // namespace
NODE_API_MODULE(tree_sitter_haskell_binding, Init)
28 changes: 28 additions & 0 deletions bindings/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 3 additions & 15 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
try {
module.exports = require("../../build/Release/tree_sitter_haskell_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_haskell_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");
Expand Down
5 changes: 5 additions & 0 deletions bindings/python/tree_sitter_haskell/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"Haskell grammar for tree-sitter"

from ._binding import language

__all__ = ["language"]
1 change: 1 addition & 0 deletions bindings/python/tree_sitter_haskell/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def language() -> int: ...
27 changes: 27 additions & 0 deletions bindings/python/tree_sitter_haskell/binding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <Python.h>

typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_haskell(void);

static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_haskell());
}

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.
41 changes: 34 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,53 @@
"description": "Haskell grammar for tree-sitter",
"repository": "github:tree-sitter/tree-sitter-haskell",
"main": "bindings/node",
"types": "bindings/node",
"keywords": [
"parser",
"haskell"
],
"author": "Rick Winfrey",
"maintainers": ["Torsten Schmits"],
"contributors": ["Max Brunsfeld", "Owen Shepherd"],
"maintainers": [
"Torsten Schmits"
],
"contributors": [
"Max Brunsfeld",
"Owen Shepherd"
],
"license": "MIT",
"files": [
"grammar.js",
"grammar/*.js",
"binding.gyp",
"prebuilds/**",
"bindings/node/*",
"queries/*",
"src/**"
],
"dependencies": {
"nan": "^2.12.1",
"node-gyp": ">=7 <11"
"node-addon-api": "^7.1.0",
"node-gyp": ">=7 <11",
"node-gyp-build": "^4.8.0"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
},
"peerDependenciesMeta": {
"tree_sitter": {
"optional": true
}
},
"devDependencies": {
"tree-sitter-cli": "^0.20.6",
"web-tree-sitter": "^0.20.6"
"prebuildify": "^6.0.0",
"tree-sitter-cli": "^0.21.0",
"web-tree-sitter": "^0.21.0"
},
"scripts": {
"test": "tree-sitter test",
"examples": "script/parse-examples",
"examples-wasm": "script/parse-examples wasm"
"examples-wasm": "script/parse-examples wasm",
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip"
},
"tree-sitter": [
{
Expand Down
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "tree-sitter-haskell"
description = "Haskell grammar for tree-sitter"
version = "0.15.0"
keywords = ["incremental", "parsing", "tree-sitter", "haskell"]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Compilers",
"Topic :: Text Processing :: Linguistic",
"Typing :: Typed"
]
requires-python = ">=3.8"
license.text = "MIT"
readme = "README.md"

[project.urls]
Homepage = "https://github.com/tree-sitter/tree-sitter-haskell"

[project.optional-dependencies]
core = ["tree-sitter~=0.21"]

[tool.cibuildwheel]
build = "cp38-*"
build-frontend = "build"
Loading

0 comments on commit 2c42e90

Please sign in to comment.