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

Bump tree-sitter version #12

Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "~0.20.10"
tree-sitter = "0.22.6"

[build-dependencies]
cc = "~1.0.83"
cc = "1.0.106"
23 changes: 17 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
"targets": [
{
"target_name": "tree_sitter_kconfig_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",
# NOTE: if your language has an external scanner, add it here.
],
"conditions": [
["OS!='win'", {
"cflags_c": [
"-std=c11",
],
}, { # OS == "win"
"cflags_c": [
"/std:c11",
"/utf-8",
],
}],
],
"cflags_c": [
"-std=c99",
]
}
]
}
38 changes: 14 additions & 24 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
#include "nan.h"
#include "tree_sitter/parser.h"
#include <node.h>
#include <napi.h>

using namespace v8;
typedef struct TSLanguage TSLanguage;

extern "C" TSLanguage *tree_sitter_kconfig();

namespace {

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

Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("kconfig").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
// "tree-sitter", "language" hashed with BLAKE2
const napi_type_tag LANGUAGE_TYPE_TAG = {
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
};

Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports["name"] = Napi::String::New(env, "kconfig");
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_kconfig());
language.TypeTag(&LANGUAGE_TYPE_TAG);
exports["language"] = language;
return exports;
}

NODE_MODULE(tree_sitter_kconfig_binding, Init)

} // namespace
NODE_API_MODULE(tree_sitter_kconfig_binding, Init)
20 changes: 4 additions & 16 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
try {
module.exports = require('../../build/Release/tree_sitter_kconfig_binding');
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require('../../build/Debug/tree_sitter_kconfig_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');
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
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
4 changes: 2 additions & 2 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_kconfig::language()).expect("Error loading Kconfig grammar");
//! parser.set_language(&tree_sitter_kconfig::language()).expect("Error loading Kconfig grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
Expand Down Expand Up @@ -45,7 +45,7 @@ mod tests {
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.set_language(&super::language())
.expect("Error loading kconfig grammar");
}
}
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,51 @@
"version": "1.1.1",
"description": "Kconfig grammar for tree-sitter",
"main": "bindings/node",
"types": "bindings/node",
"keywords": [
"parsing",
"incremental",
"kconfig"
],
"files": [
"grammar.js",
"binding.gyp",
"prebuilds/**",
"bindings/node/*",
"queries/*",
"src/**"
],
"repository": {
"type": "git",
"url": "https://github.com/amaanq/tree-sitter-kconfig.git"
},
"author": "Amaan Qureshi <[email protected]>",
"license": "MIT",
"dependencies": {
"nan": "^2.17.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": {
"eslint": ">=5.16.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-cli": "^0.20.8"
"tree-sitter-cli": "^0.20.8",
"prebuildify": "^6.0.0"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"lint": "eslint grammar.js",
"test": "tree-sitter test && script/parse-examples",
"test-windows": "tree-sitter test"
"test-windows": "tree-sitter test",
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip"
},
"tree-sitter": [
{
Expand Down
1 change: 0 additions & 1 deletion src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading