Skip to content

Commit ce2df04

Browse files
authored
Merge pull request github#17350 from hvitved/tree-sitter-0.23
Bump `tree-sitter` to `0.23.0`
2 parents 05ffb47 + eb1b2a5 commit ce2df04

File tree

21 files changed

+283
-200
lines changed

21 files changed

+283
-200
lines changed

ql/Cargo.lock

Lines changed: 37 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ql/buramu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "buramu"
33
version = "0.1.0"
4-
edition = "2018"
4+
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

ql/buramu/tree-sitter-blame/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.0.1"
55
keywords = ["incremental", "parsing", "blame"]
66
categories = ["parsing", "text-editors"]
77
repository = "https://github.com/tree-sitter/tree-sitter-blame"
8-
edition = "2018"
8+
edition = "2021"
99
license = "MIT"
1010

1111
build = "bindings/rust/build.rs"
@@ -20,10 +20,8 @@ include = [
2020
path = "bindings/rust/lib.rs"
2121

2222
[dependencies]
23-
tree-sitter = ">= 0.22.6"
23+
tree-sitter-language = "0.1.0"
24+
tree-sitter = ">= 0.23"
2425

2526
[build-dependencies]
2627
cc = "1.0"
27-
28-
[patch.crates-io]
29-
tree-sitter = {git = "https://github.com/redsun82/tree-sitter.git", rev = "1f5c1112ceaa8fc6aff61d1852690407670d2a96"}

ql/buramu/tree-sitter-blame/binding.gyp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
"targets": [
33
{
44
"target_name": "tree_sitter_blame_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": [
1012
"bindings/node/binding.cc",
1113
"src/parser.c",
12-
# If your language uses an external scanner, add it here.
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
}
Lines changed: 14 additions & 22 deletions
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_blame();
5+
extern "C" TSLanguage *tree_sitter_blame();
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_blame());
21-
22-
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("blame").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, "blame");
14+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_blame());
15+
language.TypeTag(&LANGUAGE_TYPE_TAG);
16+
exports["language"] = language;
17+
return exports;
2418
}
2519

26-
NODE_MODULE(tree_sitter_blame_binding, Init)
27-
28-
} // namespace
20+
NODE_API_MODULE(tree_sitter_blame_binding, Init)

ql/buramu/tree-sitter-blame/bindings/node/index.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
try {
2-
module.exports = require("../../build/Release/tree_sitter_blame_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_blame_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");

ql/buramu/tree-sitter-blame/bindings/rust/build.rs

Lines changed: 3 additions & 0 deletions
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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
1-
//! This crate provides blame language support for the [tree-sitter][] parsing library.
1+
//! This crate provides Blame language support for the [tree-sitter][] parsing library.
22
//!
33
//! Typically, you will use the [language][language func] function to add this language to a
44
//! tree-sitter [Parser][], and then use the parser to parse some code:
55
//!
6-
//! ```
7-
//! let code = "";
6+
//! ```ignore
7+
//! let code = r#"
8+
//! "#;
89
//! let mut parser = tree_sitter::Parser::new();
9-
//! parser.set_language(tree_sitter_blame::language()).expect("Error loading blame grammar");
10+
//! let language = tree_sitter_blame::LANGUAGE;
11+
//! parser
12+
//! .set_language(&language.into())
13+
//! .expect("Error loading Blame parser"); // fails for some reason, so code block is ignored for now
1014
//! let tree = parser.parse(code, None).unwrap();
15+
//! assert!(!tree.root_node().has_error());
1116
//! ```
1217
//!
1318
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
1419
//! [language func]: fn.language.html
1520
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
1621
//! [tree-sitter]: https://tree-sitter.github.io/
1722
18-
use tree_sitter::Language;
23+
use tree_sitter_language::LanguageFn;
1924

2025
extern "C" {
21-
fn tree_sitter_blame() -> Language;
26+
fn tree_sitter_blame() -> *const ();
2227
}
2328

24-
/// Get the tree-sitter [Language][] for this grammar.
25-
///
26-
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
27-
pub fn language() -> Language {
28-
unsafe { tree_sitter_blame() }
29-
}
29+
/// The tree-sitter [`LanguageFn`] for this grammar.
30+
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_blame) };
3031

3132
/// The content of the [`node-types.json`][] file for this grammar.
3233
///
3334
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
34-
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
35+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
3536

36-
// Uncomment these to include any queries that this grammar contains
37+
// NOTE: uncomment these to include any queries that this grammar contains:
3738

38-
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
39-
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
40-
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
41-
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
39+
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
40+
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
41+
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
42+
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
4243

4344
#[cfg(test)]
4445
mod tests {
4546
#[test]
4647
fn test_can_load_grammar() {
4748
let mut parser = tree_sitter::Parser::new();
4849
parser
49-
.set_language(super::language())
50-
.expect("Error loading blame language");
50+
.set_language(&super::LANGUAGE.into())
51+
.expect("Error loading Blame parser");
5152
}
5253
}

0 commit comments

Comments
 (0)