Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tree-sitter generate on the main branch. Update tree-sitter-cli to 0.22.6 #121

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "TreeSitterKotlin",
products: [
.library(name: "TreeSitterKotlin", targets: ["TreeSitterKotlin"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterKotlin",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
fwcd marked this conversation as resolved.
Show resolved Hide resolved
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
],
cLanguageStandard: .c11
)
25 changes: 18 additions & 7 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
"targets": [
{
"target_name": "tree_sitter_kotlin_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
"src",
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
"src/scanner.c",
"bindings/node/binding.cc"
# NOTE: if your language has an external scanner, add it here.
fwcd marked this conversation as resolved.
Show resolved Hide resolved
],
"conditions": [
["OS!='win'", {
"cflags_c": [
"-std=c11",
],
}, { # OS == "win"
"cflags_c": [
"/std:c11",
"/utf-8",
],
}],
],
"cflags_c": [
"-std=c99",
]
}
]
}
11 changes: 11 additions & 0 deletions bindings/c/tree-sitter-kotlin.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-kotlin
Description: Kotlin grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-kotlin
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_kotlin

// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
fwcd marked this conversation as resolved.
Show resolved Hide resolved
// // 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_kotlin())
}
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_kotlin_test

import (
"testing"

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

func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_kotlin.Language())
if language == nil {
t.Errorf("Error loading Kotlin 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-kotlin

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_kotlin();
extern "C" TSLanguage *tree_sitter_kotlin();

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

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

NODE_MODULE(tree_sitter_kotlin_binding, Init)

} // namespace
NODE_API_MODULE(tree_sitter_kotlin_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_kotlin_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_kotlin_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_kotlin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"Kotlin grammar for tree-sitter"

from ._binding import language

__all__ = ["language"]
1 change: 1 addition & 0 deletions bindings/python/tree_sitter_kotlin/__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_kotlin/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_kotlin(void);

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

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.
3 changes: 3 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 16 additions & 0 deletions bindings/swift/TreeSitterKotlin/kotlin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_KOTLIN_H_
#define TREE_SITTER_KOTLIN_H_

typedef struct TSLanguage TSLanguage;

#ifdef __cplusplus
extern "C" {
#endif

const TSLanguage *tree_sitter_kotlin(void);

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_KOTLIN_H_
33 changes: 28 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "0.3.7",
"description": "Tree-sitter grammar for Kotlin",
"main": "bindings/node",
"types": "bindings/node",
"scripts": {
"test": "tree-sitter test",
"install": "node-gyp rebuild",
"install": "node-gyp-build",
"generate": "tree-sitter generate",
"parse": "tree-sitter parse",
"build-wasm": "tree-sitter build-wasm",
"playground": "tree-sitter playground"
"playground": "tree-sitter playground",
"prebuildify": "prebuildify --napi --strip"
},
"repository": {
"type": "git",
Expand All @@ -20,6 +22,14 @@
"kotlin",
"grammar"
],
"files": [
"grammar.js",
"binding.gyp",
"prebuilds/**",
"bindings/node/*",
"queries/*",
"src/**"
],
"author": "fwcd",
"license": "MIT",
"gypfile": true,
Expand All @@ -28,15 +38,28 @@
},
"homepage": "https://github.com/fwcd/tree-sitter-kotlin#readme",
"dependencies": {
"nan": "^2.19.0"
"node-addon-api": "^7.1.0",
"node-gyp-build": "^4.8.0"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
},
"peerDependenciesMeta": {
"tree_sitter": {
"optional": true
}
},
"devDependencies": {
"tree-sitter-cli": "^0.22.1"
"tree-sitter-cli": "^0.22.6",
"prebuildify": "^6.0.0"
},
"tree-sitter": [
{
"scope": "source.kotlin",
"file-types": ["kt", "kts"]
"file-types": [
"kt",
"kts"
]
}
]
}
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-kotlin"
description = "Kotlin grammar for tree-sitter"
version = "0.0.1"
keywords = ["incremental", "parsing", "tree-sitter", "kotlin"]
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-kotlin"

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

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