Skip to content

Commit 1cb1da3

Browse files
author
tianhuan
committed
Upgrade tree-sitter-cli to 0.19.4
1 parent 4a0f82d commit 1cb1da3

File tree

12 files changed

+383461
-382937
lines changed

12 files changed

+383461
-382937
lines changed

Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "tree-sitter-c_sharp"
3+
description = "c_sharp grammar for the tree-sitter parsing library"
4+
version = "0.0.1"
5+
keywords = ["incremental", "parsing", "c_sharp"]
6+
categories = ["parsing", "text-editors"]
7+
repository = "https://github.com/tree-sitter/tree-sitter-javascript"
8+
edition = "2018"
9+
license = "MIT"
10+
11+
build = "bindings/rust/build.rs"
12+
include = [
13+
"bindings/rust/*",
14+
"grammar.js",
15+
"queries/*",
16+
"src/*",
17+
]
18+
19+
[lib]
20+
path = "bindings/rust/lib.rs"
21+
22+
[dependencies]
23+
tree-sitter = "0.17"
24+
25+
[build-dependencies]
26+
cc = "1.0"

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"sources": [
1010
"src/parser.c",
1111
"src/scanner.c",
12-
"src/binding.cc"
12+
"bindings/node/binding.cc"
1313
],
1414
"cflags_c": [
1515
"-std=c99",
File renamed without changes.

bindings/node/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
try {
2+
module.exports = require("../../build/Release/tree_sitter_c_sharp_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_c_sharp_binding");
9+
} catch (error2) {
10+
if (error2.code !== 'MODULE_NOT_FOUND') {
11+
throw error2;
12+
}
13+
throw error1
14+
}
15+
}
16+
17+
try {
18+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
19+
} catch (_) {}

bindings/rust/build.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
fn main() {
2+
let src_dir = std::path::Path::new("src");
3+
4+
let mut c_config = cc::Build::new();
5+
c_config.include(&src_dir);
6+
c_config
7+
.flag_if_supported("-Wno-unused-parameter")
8+
.flag_if_supported("-Wno-unused-but-set-variable")
9+
.flag_if_supported("-Wno-trigraphs");
10+
let parser_path = src_dir.join("parser.c");
11+
c_config.file(&parser_path);
12+
13+
// If your language uses an external scanner written in C,
14+
// then include this block of code:
15+
16+
/*
17+
let scanner_path = src_dir.join("scanner.c");
18+
c_config.file(&scanner_path);
19+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
20+
*/
21+
22+
c_config.compile("parser");
23+
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
24+
25+
// If your language uses an external scanner written in C++,
26+
// then include this block of code:
27+
28+
/*
29+
let mut cpp_config = cc::Build::new();
30+
cpp_config.cpp(true);
31+
cpp_config.include(&src_dir);
32+
cpp_config
33+
.flag_if_supported("-Wno-unused-parameter")
34+
.flag_if_supported("-Wno-unused-but-set-variable");
35+
let scanner_path = src_dir.join("scanner.cc");
36+
cpp_config.file(&scanner_path);
37+
cpp_config.compile("scanner");
38+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
39+
*/
40+
}

bindings/rust/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! This crate provides c_sharp language support for the [tree-sitter][] parsing library.
2+
//!
3+
//! Typically, you will use the [language][language func] function to add this language to a
4+
//! tree-sitter [Parser][], and then use the parser to parse some code:
5+
//!
6+
//! ```
7+
//! let code = "";
8+
//! let mut parser = tree_sitter::Parser::new();
9+
//! parser.set_language(tree_sitter_c_sharp::language()).expect("Error loading c_sharp grammar");
10+
//! let tree = parser.parse(code, None).unwrap();
11+
//! ```
12+
//!
13+
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14+
//! [language func]: fn.language.html
15+
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16+
//! [tree-sitter]: https://tree-sitter.github.io/
17+
18+
use tree_sitter::Language;
19+
20+
extern "C" {
21+
fn tree_sitter_c_sharp() -> Language;
22+
}
23+
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_c_sharp() }
29+
}
30+
31+
/// The content of the [`node-types.json`][] file for this grammar.
32+
///
33+
/// [`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+
36+
// Uncomment these to include any queries that this grammar contains
37+
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");
42+
43+
#[cfg(test)]
44+
mod tests {
45+
#[test]
46+
fn test_can_load_grammar() {
47+
let mut parser = tree_sitter::Parser::new();
48+
parser
49+
.set_language(super::language())
50+
.expect("Error loading c_sharp language");
51+
}
52+
}

index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tree-sitter-c-sharp",
33
"version": "0.16.1",
44
"description": "C# grammar for tree-sitter",
5-
"main": "index.js",
5+
"main": "bindings/node",
66
"keywords": [
77
"parser",
88
"lexer"
@@ -13,7 +13,7 @@
1313
"nan": "^2.12.0"
1414
},
1515
"devDependencies": {
16-
"tree-sitter-cli": "^0.17.1"
16+
"tree-sitter-cli": "^0.19.4"
1717
},
1818
"scripts": {
1919
"test": "tree-sitter test && node test.js"

src/grammar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9237,6 +9237,7 @@
92379237
"variable_declarator"
92389238
]
92399239
],
9240+
"precedences": [],
92409241
"externals": [
92419242
{
92429243
"type": "SYMBOL",

0 commit comments

Comments
 (0)