Skip to content

Commit 7f6b436

Browse files
author
Vladimir Makayev
committed
run tree-sitter generate
1 parent c9cb850 commit 7f6b436

21 files changed

+3338
-6441
lines changed

Package.swift

+47
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: "TreeSitterKotlin",
6+
products: [
7+
.library(name: "TreeSitterKotlin", targets: ["TreeSitterKotlin"]),
8+
],
9+
dependencies: [],
10+
targets: [
11+
.target(name: "TreeSitterKotlin",
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

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
"targets": [
33
{
44
"target_name": "tree_sitter_kotlin_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": [
12+
"bindings/node/binding.cc",
1013
"src/parser.c",
11-
"src/scanner.c",
12-
"bindings/node/binding.cc"
14+
# NOTE: if your language has an external scanner, add it here.
15+
],
16+
"conditions": [
17+
["OS!='win'", {
18+
"cflags_c": [
19+
"-std=c11",
20+
],
21+
}, { # OS == "win"
22+
"cflags_c": [
23+
"/std:c11",
24+
"/utf-8",
25+
],
26+
}],
1327
],
14-
"cflags_c": [
15-
"-std=c99",
16-
]
1728
}
1829
]
1930
}

bindings/c/tree-sitter-kotlin.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-kotlin
6+
Description: Kotlin grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-kotlin
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_kotlin
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_kotlin())
13+
}

bindings/go/binding_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package tree_sitter_kotlin_test
2+
3+
import (
4+
"testing"
5+
6+
tree_sitter "github.com/smacker/go-tree-sitter"
7+
"github.com/tree-sitter/tree-sitter-kotlin"
8+
)
9+
10+
func TestCanLoadGrammar(t *testing.T) {
11+
language := tree_sitter.NewLanguage(tree_sitter_kotlin.Language())
12+
if language == nil {
13+
t.Errorf("Error loading Kotlin 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-kotlin
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_kotlin();
5+
extern "C" TSLanguage *tree_sitter_kotlin();
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_kotlin());
21-
22-
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("kotlin").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, "kotlin");
14+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_kotlin());
15+
language.TypeTag(&LANGUAGE_TYPE_TAG);
16+
exports["language"] = language;
17+
return exports;
2418
}
2519

26-
NODE_MODULE(tree_sitter_kotlin_binding, Init)
27-
28-
} // namespace
20+
NODE_API_MODULE(tree_sitter_kotlin_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_kotlin_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_kotlin_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+
"Kotlin 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_kotlin(void);
6+
7+
static PyObject* _binding_language(PyObject *self, PyObject *args) {
8+
return PyLong_FromVoidPtr(tree_sitter_kotlin());
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_kotlin/py.typed

Whitespace-only changes.

bindings/rust/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fn main() {
77
.flag_if_supported("-Wno-unused-parameter")
88
.flag_if_supported("-Wno-unused-but-set-variable")
99
.flag_if_supported("-Wno-trigraphs");
10+
#[cfg(target_env = "msvc")]
11+
c_config.flag("-utf-8");
12+
1013
let parser_path = src_dir.join("parser.c");
1114
c_config.file(&parser_path);
1215

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TREE_SITTER_KOTLIN_H_
2+
#define TREE_SITTER_KOTLIN_H_
3+
4+
typedef struct TSLanguage TSLanguage;
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
const TSLanguage *tree_sitter_kotlin(void);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif // TREE_SITTER_KOTLIN_H_

package.json

+28-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"version": "0.3.7",
44
"description": "Tree-sitter grammar for Kotlin",
55
"main": "bindings/node",
6+
"types": "bindings/node",
67
"scripts": {
78
"test": "tree-sitter test",
8-
"install": "node-gyp rebuild",
9+
"install": "node-gyp-build",
910
"generate": "tree-sitter generate",
1011
"parse": "tree-sitter parse",
1112
"build-wasm": "tree-sitter build-wasm",
12-
"playground": "tree-sitter playground"
13+
"playground": "tree-sitter playground",
14+
"prebuildify": "prebuildify --napi --strip"
1315
},
1416
"repository": {
1517
"type": "git",
@@ -20,6 +22,14 @@
2022
"kotlin",
2123
"grammar"
2224
],
25+
"files": [
26+
"grammar.js",
27+
"binding.gyp",
28+
"prebuilds/**",
29+
"bindings/node/*",
30+
"queries/*",
31+
"src/**"
32+
],
2333
"author": "fwcd",
2434
"license": "MIT",
2535
"gypfile": true,
@@ -28,15 +38,28 @@
2838
},
2939
"homepage": "https://github.com/fwcd/tree-sitter-kotlin#readme",
3040
"dependencies": {
31-
"nan": "^2.19.0"
41+
"node-addon-api": "^7.1.0",
42+
"node-gyp-build": "^4.8.0"
43+
},
44+
"peerDependencies": {
45+
"tree-sitter": "^0.21.0"
46+
},
47+
"peerDependenciesMeta": {
48+
"tree_sitter": {
49+
"optional": true
50+
}
3251
},
3352
"devDependencies": {
34-
"tree-sitter-cli": "^0.22.1"
53+
"tree-sitter-cli": "^0.22.6",
54+
"prebuildify": "^6.0.0"
3555
},
3656
"tree-sitter": [
3757
{
3858
"scope": "source.kotlin",
39-
"file-types": ["kt", "kts"]
59+
"file-types": [
60+
"kt",
61+
"kts"
62+
]
4063
}
4164
]
4265
}

pyproject.toml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "tree-sitter-kotlin"
7+
description = "Kotlin grammar for tree-sitter"
8+
version = "0.0.1"
9+
keywords = ["incremental", "parsing", "tree-sitter", "kotlin"]
10+
classifiers = [
11+
"Intended Audience :: Developers",
12+
"License :: OSI Approved :: MIT License",
13+
"Topic :: Software Development :: Compilers",
14+
"Topic :: Text Processing :: Linguistic",
15+
"Typing :: Typed"
16+
]
17+
requires-python = ">=3.8"
18+
license.text = "MIT"
19+
readme = "README.md"
20+
21+
[project.urls]
22+
Homepage = "https://github.com/tree-sitter/tree-sitter-kotlin"
23+
24+
[project.optional-dependencies]
25+
core = ["tree-sitter~=0.21"]
26+
27+
[tool.cibuildwheel]
28+
build = "cp38-*"
29+
build-frontend = "build"

0 commit comments

Comments
 (0)