Skip to content

Commit 530f0f2

Browse files
committed
Bump tree-sitter-cli to 0.19
1 parent be2e415 commit 530f0f2

File tree

13 files changed

+252
-141
lines changed

13 files changed

+252
-141
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
build
33
*.log
44
package-lock.json
5+
Cargo.lock
6+
target

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
grammar_test
21
build
32
script
3+
target
4+
Cargo.lock

Cargo.toml

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

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"sources": [
1010
"src/parser.c",
11-
"src/binding.cc"
11+
"bindings/node/binding.cc"
1212
],
1313
"cflags_c": [
1414
"-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_regex_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_regex_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+
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
23+
c_config.compile("parser");
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+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
38+
cpp_config.compile("scanner");
39+
*/
40+
}

bindings/rust/lib.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! This crate provides regex 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_regex::language()).expect("Error loading regex 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_regex() -> 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_regex() }
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+
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
37+
38+
#[cfg(test)]
39+
mod tests {
40+
#[test]
41+
fn test_can_load_grammar() {
42+
let mut parser = tree_sitter::Parser::new();
43+
parser
44+
.set_language(super::language())
45+
.expect("Error loading regex language");
46+
}
47+
}

index.js

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
"name": "tree-sitter-regex",
33
"version": "0.16.0",
44
"description": "regex grammar for tree-sitter",
5-
"main": "index.js",
5+
"main": "bindings/node",
66
"keywords": [
77
"parser",
88
"regex"
99
],
1010
"author": "Ashi Krishnan <queerviolet@github.com>",
1111
"license": "MIT",
1212
"dependencies": {
13-
"nan": "^2.14.0"
13+
"nan": "^2.14.1"
1414
},
1515
"devDependencies": {
16-
"tree-sitter-cli": "^0.16.7"
16+
"tree-sitter-cli": "^0.19.1"
1717
},
1818
"scripts": {
1919
"test": "tree-sitter test"

src/grammar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@
670670
}
671671
],
672672
"conflicts": [],
673+
"precedences": [],
673674
"externals": [],
674675
"inline": [
675676
"_character_escape",

0 commit comments

Comments
 (0)