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

chore: update tree-sitter to 0.22.5 and bump crate to 1.6.0 #19

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
@@ -1,6 +1,6 @@
[package]
name = "tree-sitter-capnp"
version = "1.5.0"
version = "1.6.0"
authors = ["Amaan Qureshi <[email protected]>"]
autoexamples = false
categories = ["parsing", "text-editors"]
Expand All @@ -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.5"

[build-dependencies]
cc = "~1.0"
12 changes: 5 additions & 7 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "nan.h"
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"

using namespace v8;

extern "C" TSLanguage *tree_sitter_capnp();
extern "C" TSLanguage * tree_sitter_capnp();

namespace {

Expand All @@ -16,15 +16,13 @@ void Init(Local<Object> exports, Local<Object> module) {
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance =
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_capnp());

Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("capnp").ToLocalChecked());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("capnp").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}

NODE_MODULE(tree_sitter_capnp_binding, Init)

} // namespace
} // namespace
8 changes: 4 additions & 4 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
try {
module.exports = require('../../build/Release/tree_sitter_capnp_binding');
module.exports = require("../../build/Release/tree_sitter_capnp_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require('../../build/Debug/tree_sitter_capnp_binding');
module.exports = require("../../build/Debug/tree_sitter_capnp_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1;
throw error1
}
}

try {
module.exports.nodeTypeInfo = require('../../src/node-types.json');
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
4 changes: 2 additions & 2 deletions bindings/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ way.)

```toml
[dependencies]
tree-sitter = "~0.20.3"
tree-sitter-capnp = "1.5.0"
tree-sitter = "~0.22.5"
tree-sitter-capnp = "1.6.0"
```

Typically, you will use the [language][language func] function to add this
Expand Down
27 changes: 26 additions & 1 deletion bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ fn main() {
let src_dir = std::path::Path::new("src");

let mut c_config = cc::Build::new();
c_config.include(src_dir);
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);

// If your language uses an external scanner written in C,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @amaanq, would you mind reviewing this draft before I turn it into a PR? I ran npm run build to regenerate the bindings but I see it included a bunch of commented blocks, including some that look like they should be preserved. See https://github.com/tree-sitter-grammars/tree-sitter-capnp/pull/19/files#diff-f1aca5f9358053e570c736ccd84ad4e75fc98048bb3bfbb16fa173d4555f48c5L31-L49

// then include this block of code:

/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/

c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

// If your language uses an external scanner written in C++,
// then include this block of code:

/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}
34 changes: 11 additions & 23 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! This crate provides Cap'n Proto language support for the [tree-sitter][] parsing library.
//! This crate provides capnp language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_capnp::language()).expect("Error loading Cap'n Proto grammar");
//! parser.set_language(tree_sitter_capnp::language()).expect("Error loading capnp grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
Expand All @@ -28,29 +28,17 @@ pub fn language() -> Language {
unsafe { tree_sitter_capnp() }
}

/// The content of the [`node-types.json`][] file for this grammar.
/// The source of the Rust tree-sitter grammar description.
pub const GRAMMAR: &str = include_str!("../../grammar.js");

/// The folds query for this language.
pub const FOLDS_QUERY: &str = include_str!("../../queries/folds.scm");

/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");

/// The indents query for this language.
pub const INDENTS_QUERY: &str = include_str!("../../queries/indents.scm");

/// The injection query for this language.
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");

/// The symbol tagging query for this language.
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");

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

// Uncomment these to include any queries that this grammar contains

// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");

#[cfg(test)]
mod tests {
Expand All @@ -59,6 +47,6 @@ mod tests {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading Cap'n Proto grammar");
.expect("Error loading capnp language");
}
}
16 changes: 0 additions & 16 deletions bindings/swift/capnp.h

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tree-sitter-capnp",
"version": "1.5.0",
"version": "1.6.0",
"description": "Cap'n Proto grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
Expand All @@ -16,12 +16,12 @@
},
"homepage": "https://github.com/amaanq/tree-sitter-capnp#readme",
"dependencies": {
"nan": "^2.17.0"
"nan": "^2.19.0"
},
"devDependencies": {
"eslint": "^8.32.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-cli": "^0.20.7"
"tree-sitter-cli": "^0.22.5"
},
"repository": "https://github.com/amaanq/tree-sitter-capnp",
"scripts": {
Expand Down
Loading