Skip to content

Commit b3b6597

Browse files
committed
fix: rust binding
1 parent 7d263d3 commit b3b6597

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "nu grammar for the tree-sitter parsing library"
44
version = "0.0.1"
55
keywords = ["incremental", "parsing", "nu"]
66
categories = ["parsing", "text-editors"]
7-
repository = "https://github.com/tree-sitter/tree-sitter-nu"
7+
repository = "https://github.com/nushell/tree-sitter-nu"
88
edition = "2018"
99
license = "MIT"
1010

bindings/rust/build.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,21 @@ fn main() {
22
let src_dir = std::path::Path::new("src");
33

44
let mut c_config = cc::Build::new();
5-
c_config.include(src_dir);
65
c_config
7-
.flag_if_supported("-Wno-unused-parameter")
8-
.flag_if_supported("-Wno-unused-but-set-variable")
9-
.flag_if_supported("-Wno-trigraphs");
6+
.std("c11")
7+
.include(src_dir)
8+
.flag_if_supported("-Wno-unused-value");
9+
1010
#[cfg(target_env = "msvc")]
1111
c_config.flag("-utf-8");
1212

1313
let parser_path = src_dir.join("parser.c");
1414
c_config.file(&parser_path);
15-
16-
// If your language uses an external scanner written in C,
17-
// then include this block of code:
15+
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
1816

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

23-
c_config.compile("parser");
24-
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
25-
26-
// If your language uses an external scanner written in C++,
27-
// then include this block of code:
28-
29-
/*
30-
let mut cpp_config = cc::Build::new();
31-
cpp_config.cpp(true);
32-
cpp_config.include(&src_dir);
33-
cpp_config
34-
.flag_if_supported("-Wno-unused-parameter")
35-
.flag_if_supported("-Wno-unused-but-set-variable");
36-
let scanner_path = src_dir.join("scanner.cc");
37-
cpp_config.file(&scanner_path);
38-
cpp_config.compile("scanner");
39-
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
40-
*/
21+
c_config.compile("tree-sitter-nu");
4122
}

bindings/rust/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! This crate provides Nu language support for the [tree-sitter][] parsing library.
22
//!
3-
//! Typically, you will use the [language][language func] function to add this language to a
3+
//! Typically, you will use the [LANGUAGE][] constant to add this language to a
44
//! tree-sitter [Parser][], and then use the parser to parse some code:
55
//!
66
//! ```
7+
//! use tree_sitter::Parser;
8+
//!
79
//! let code = r#"
10+
//! echo "hello world!"
811
//! "#;
9-
//! let mut parser = tree_sitter::Parser::new();
12+
//! let mut parser = Parser::new();
1013
//! let language = tree_sitter_nu::LANGUAGE;
1114
//! parser
1215
//! .set_language(&language.into())
@@ -15,8 +18,6 @@
1518
//! assert!(!tree.root_node().has_error());
1619
//! ```
1720
//!
18-
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
19-
//! [language func]: fn.language.html
2021
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
2122
//! [tree-sitter]: https://tree-sitter.github.io/
2223
@@ -26,20 +27,18 @@ extern "C" {
2627
fn tree_sitter_nu() -> *const ();
2728
}
2829

29-
/// The tree-sitter [`LanguageFn`] for this grammar.
30+
/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar.
31+
///
32+
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
3033
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_nu) };
3134

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

37-
// NOTE: uncomment these to include any queries that this grammar contains:
38-
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");
40+
/// The syntax highlighting query for this grammar.
41+
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/nu/highlights.scm");
4342

4443
#[cfg(test)]
4544
mod tests {

0 commit comments

Comments
 (0)