-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update tree-sitter version and also start working on more luaCATS
- Loading branch information
Showing
44 changed files
with
2,198 additions
and
1,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
|
||
[*.{json,toml,yml,gyp}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.{c,cc,h}] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.rs] | ||
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 | ||
|
||
[parser.c] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "TreeSitterLua", | ||
products: [ | ||
.library(name: "TreeSitterLua", targets: ["TreeSitterLua"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "TreeSitterLua", | ||
dependencies: [], | ||
path: ".", | ||
sources: [ | ||
"src/parser.c", | ||
// NOTE: if your language has an external scanner, add it here. | ||
], | ||
resources: [ | ||
.copy("queries") | ||
], | ||
publicHeadersPath: "bindings/swift", | ||
cSettings: [.headerSearchPath("src")] | ||
), | ||
.testTarget( | ||
name: "TreeSitterLuaTests", | ||
dependencies: [ | ||
"SwiftTreeSitter", | ||
"TreeSitterLua", | ||
], | ||
path: "bindings/swift/TreeSitterLuaTests" | ||
) | ||
], | ||
cLanguageStandard: .c11 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TREE_SITTER_LUA_H_ | ||
#define TREE_SITTER_LUA_H_ | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
const TSLanguage *tree_sitter_lua(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TREE_SITTER_LUA_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix=@PREFIX@ | ||
libdir=@LIBDIR@ | ||
includedir=@INCLUDEDIR@ | ||
|
||
Name: tree-sitter-lua | ||
Description: Lua grammar for tree-sitter | ||
URL: @URL@ | ||
Version: @VERSION@ | ||
Requires: @REQUIRES@ | ||
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-lua | ||
Cflags: -I${includedir} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tree_sitter_lua | ||
|
||
// #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_lua()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tree_sitter_lua_test | ||
|
||
import ( | ||
"testing" | ||
|
||
tree_sitter "github.com/tree-sitter/go-tree-sitter" | ||
tree_sitter_lua "github.com/tree-sitter/tree-sitter-lua/bindings/go" | ||
) | ||
|
||
func TestCanLoadGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_lua.Language()) | ||
if language == nil { | ||
t.Errorf("Error loading Lua grammar") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_lua(); | ||
extern "C" TSLanguage *tree_sitter_lua(); | ||
|
||
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_lua()); | ||
|
||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("lua").ToLocalChecked()); | ||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); | ||
Napi::Object Init(Napi::Env env, Napi::Object exports) { | ||
exports["name"] = Napi::String::New(env, "lua"); | ||
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_lua()); | ||
language.TypeTag(&LANGUAGE_TYPE_TAG); | ||
exports["language"] = language; | ||
return exports; | ||
} | ||
|
||
NODE_MODULE(tree_sitter_lua_binding, Init) | ||
|
||
} // namespace | ||
NODE_API_MODULE(tree_sitter_lua_binding, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference types="node" /> | ||
|
||
const assert = require("node:assert"); | ||
const { test } = require("node:test"); | ||
|
||
test("can load grammar", () => { | ||
const parser = new (require("tree-sitter"))(); | ||
assert.doesNotThrow(() => parser.setLanguage(require("."))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from unittest import TestCase | ||
|
||
import tree_sitter, tree_sitter_lua | ||
|
||
|
||
class TestLanguage(TestCase): | ||
def test_can_load_grammar(self): | ||
try: | ||
tree_sitter.Language(tree_sitter_lua.language()) | ||
except Exception: | ||
self.fail("Error loading Lua grammar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Lua grammar for tree-sitter""" | ||
|
||
from importlib.resources import files as _files | ||
|
||
from ._binding import language | ||
|
||
|
||
def _get_query(name, file): | ||
query = _files(f"{__package__}.queries") / file | ||
globals()[name] = query.read_text() | ||
return globals()[name] | ||
|
||
|
||
def __getattr__(name): | ||
# NOTE: uncomment these to include any queries that this grammar contains: | ||
|
||
# if name == "HIGHLIGHTS_QUERY": | ||
# return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") | ||
# if name == "INJECTIONS_QUERY": | ||
# return _get_query("INJECTIONS_QUERY", "injections.scm") | ||
# if name == "LOCALS_QUERY": | ||
# return _get_query("LOCALS_QUERY", "locals.scm") | ||
# if name == "TAGS_QUERY": | ||
# return _get_query("TAGS_QUERY", "tags.scm") | ||
|
||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | ||
|
||
|
||
__all__ = [ | ||
"language", | ||
# "HIGHLIGHTS_QUERY", | ||
# "INJECTIONS_QUERY", | ||
# "LOCALS_QUERY", | ||
# "TAGS_QUERY", | ||
] | ||
|
||
|
||
def __dir__(): | ||
return sorted(__all__ + [ | ||
"__all__", "__builtins__", "__cached__", "__doc__", "__file__", | ||
"__loader__", "__name__", "__package__", "__path__", "__spec__", | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Final | ||
|
||
# NOTE: uncomment these to include any queries that this grammar contains: | ||
|
||
# HIGHLIGHTS_QUERY: Final[str] | ||
# INJECTIONS_QUERY: Final[str] | ||
# LOCALS_QUERY: Final[str] | ||
# TAGS_QUERY: Final[str] | ||
|
||
def language() -> object: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <Python.h> | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
TSLanguage *tree_sitter_lua(void); | ||
|
||
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { | ||
return PyCapsule_New(tree_sitter_lua(), "tree_sitter.Language", NULL); | ||
} | ||
|
||
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.
Oops, something went wrong.