tree-sitter-sh 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +9 -7
- package/README.md +6 -2
- package/bindings/rust/build.rs +20 -6
- package/bindings/rust/lib.rs +3 -47
- package/grammar.js +297 -298
- package/package.json +8 -3
- package/src/arithmetic.h +103 -110
- package/src/grammar.json +2073 -1962
- package/src/input.h +0 -1
- package/src/lexical-tokens.h +2 -0
- package/src/lexical-tokens.json +4 -2
- package/src/parser.c +2 -2
- package/src/scanner.c +2071 -2250
- package/src/source.h +31 -12
- package/test/bindings.test.rs +274 -0
- package/tree-sitter.json +5 -10
package/Cargo.toml
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "tree-sitter-sh"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.17.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
description = "Tree-sitter grammar for POSIX sh."
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "https://github.com/konomanoasa/tree-sitter-sh"
|
|
8
8
|
license = "MIT"
|
|
9
|
-
keywords = ["incremental", "parsing", "sh", "tree-sitter"]
|
|
10
|
-
categories = ["parser-implementations", "parsing", "text-editors"]
|
|
11
9
|
build = "bindings/rust/build.rs"
|
|
10
|
+
links = "tree-sitter-sh"
|
|
12
11
|
include = [
|
|
13
12
|
"/LICENSE",
|
|
14
13
|
"/README.md",
|
|
15
14
|
"/bindings/rust/*.rs",
|
|
16
|
-
"/grammar.js",
|
|
17
15
|
"/queries/*.scm",
|
|
18
16
|
"/src/*.c",
|
|
19
17
|
"/src/*.h",
|
|
20
|
-
"/src
|
|
18
|
+
"/src/node-types.json",
|
|
21
19
|
"/src/tree_sitter/*.h",
|
|
22
|
-
"/
|
|
20
|
+
"/test/bindings.test.rs",
|
|
23
21
|
]
|
|
24
22
|
|
|
25
23
|
[lib]
|
|
26
24
|
path = "bindings/rust/lib.rs"
|
|
27
25
|
|
|
26
|
+
[[test]]
|
|
27
|
+
name = "bindings"
|
|
28
|
+
path = "test/bindings.test.rs"
|
|
29
|
+
|
|
28
30
|
[dependencies]
|
|
29
31
|
tree-sitter-language = "0.1.8"
|
|
30
32
|
|
|
@@ -32,4 +34,4 @@ tree-sitter-language = "0.1.8"
|
|
|
32
34
|
tree-sitter = "0.27.0"
|
|
33
35
|
|
|
34
36
|
[build-dependencies]
|
|
35
|
-
cc = "1.4
|
|
37
|
+
cc = "1.4"
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# tree-sitter-sh
|
|
2
2
|
|
|
3
|
-
[](https://github.com/konomanoasa/tree-sitter-sh/actions/workflows/ci.yaml)
|
|
4
|
+
[](https://crates.io/crates/tree-sitter-sh)
|
|
4
5
|
[](https://www.npmjs.com/package/tree-sitter-sh)
|
|
5
6
|
|
|
6
7
|
[Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for the
|
|
@@ -14,9 +15,12 @@ npm install tree-sitter-sh
|
|
|
14
15
|
|
|
15
16
|
## Development
|
|
16
17
|
|
|
18
|
+
Development uses Node.js 24 or later.
|
|
19
|
+
|
|
17
20
|
```sh
|
|
18
21
|
npm install
|
|
19
|
-
npm run
|
|
22
|
+
npm run build
|
|
23
|
+
npm test
|
|
20
24
|
```
|
|
21
25
|
|
|
22
26
|
## Specification
|
package/bindings/rust/build.rs
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
use std::{env, path::Path};
|
|
2
|
+
|
|
1
3
|
fn main() {
|
|
2
|
-
|
|
4
|
+
let mut build = cc::Build::new();
|
|
5
|
+
build.std("c17");
|
|
6
|
+
if build.get_compiler().is_like_msvc() {
|
|
7
|
+
build.flag("-utf-8");
|
|
8
|
+
}
|
|
9
|
+
if env::var("TARGET").expect("Cargo must provide TARGET")
|
|
10
|
+
== "wasm32-unknown-unknown"
|
|
11
|
+
{
|
|
12
|
+
let headers = env::var_os("DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS")
|
|
13
|
+
.expect("tree-sitter-language must provide WebAssembly headers");
|
|
14
|
+
build.include(&headers);
|
|
15
|
+
println!("cargo::rerun-if-changed={}", Path::new(&headers).display());
|
|
16
|
+
}
|
|
3
17
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
println!("cargo::rerun-if-changed=src");
|
|
19
|
+
build
|
|
20
|
+
.include("src")
|
|
21
|
+
.files(["src/parser.c", "src/scanner.c"])
|
|
22
|
+
.compile("tree-sitter-sh");
|
|
9
23
|
}
|
package/bindings/rust/lib.rs
CHANGED
|
@@ -1,56 +1,12 @@
|
|
|
1
|
-
//! POSIX.1-2024 Shell Command Language support for Tree-sitter.
|
|
2
|
-
//!
|
|
3
|
-
//! ```
|
|
4
|
-
//! let mut parser = tree_sitter::Parser::new();
|
|
5
|
-
//! parser.set_language(&tree_sitter_sh::LANGUAGE.into()).unwrap();
|
|
6
|
-
//! let tree = parser.parse("echo hello\n", None).unwrap();
|
|
7
|
-
//! assert!(!tree.root_node().has_error());
|
|
8
|
-
//! ```
|
|
9
|
-
|
|
10
1
|
use tree_sitter_language::LanguageFn;
|
|
11
2
|
|
|
12
3
|
unsafe extern "C" {
|
|
13
|
-
|
|
4
|
+
fn tree_sitter_sh() -> *const ();
|
|
14
5
|
}
|
|
15
6
|
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
pub const LANGUAGE: LanguageFn =
|
|
8
|
+
unsafe { LanguageFn::from_raw(tree_sitter_sh) };
|
|
18
9
|
|
|
19
|
-
/// Public node types and fields in Tree-sitter's JSON format.
|
|
20
10
|
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
21
11
|
|
|
22
|
-
/// Highlight query using standard Tree-sitter and Neovim captures.
|
|
23
12
|
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
|
24
|
-
|
|
25
|
-
#[cfg(test)]
|
|
26
|
-
mod tests {
|
|
27
|
-
use tree_sitter::{Parser, Query, QueryCursor, StreamingIterator};
|
|
28
|
-
|
|
29
|
-
#[test]
|
|
30
|
-
fn parses_quoted_here_document_and_highlights_its_terminator() {
|
|
31
|
-
let source = "cat <<'EOF'\n$HOME\nEOF\n";
|
|
32
|
-
let language = super::LANGUAGE.into();
|
|
33
|
-
let mut parser = Parser::new();
|
|
34
|
-
parser.set_language(&language).unwrap();
|
|
35
|
-
let tree = parser.parse(source, None).unwrap();
|
|
36
|
-
let root = tree.root_node();
|
|
37
|
-
assert_eq!(root.kind(), "program");
|
|
38
|
-
assert_eq!(root.byte_range(), 0..source.len());
|
|
39
|
-
assert!(!root.has_error(), "{}", root.to_sexp());
|
|
40
|
-
|
|
41
|
-
let query = Query::new(&language, super::HIGHLIGHTS_QUERY).unwrap();
|
|
42
|
-
let mut cursor = QueryCursor::new();
|
|
43
|
-
let mut captures = cursor.captures(&query, root, source.as_bytes());
|
|
44
|
-
let mut terminators = 0;
|
|
45
|
-
while let Some((matched, index)) = captures.next() {
|
|
46
|
-
let capture = matched.captures()[*index];
|
|
47
|
-
if capture.node.kind() == "here_document_end_text" {
|
|
48
|
-
assert_eq!(query.capture_names()[capture.index as usize], "label");
|
|
49
|
-
assert_eq!(capture.node.byte_range(), 18..21);
|
|
50
|
-
assert_eq!(capture.node.utf8_text(source.as_bytes()).unwrap(), "EOF");
|
|
51
|
-
terminators += 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
assert_eq!(terminators, 1);
|
|
55
|
-
}
|
|
56
|
-
}
|