tree-sitter-sed 0.7.0 → 0.8.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 +43 -0
- package/README.md +6 -4
- package/bindings/rust/build.rs +40 -0
- package/bindings/rust/lib.rs +70 -0
- package/common/grammar.js +213 -257
- package/common/regex.js +38 -92
- package/common/scanner.h +766 -1112
- package/package.json +7 -8
- package/queries/highlights.scm +2 -5
- package/sed_ere/queries/highlights.scm +2 -5
- package/sed_ere/src/grammar.json +724 -1282
- package/sed_ere/src/node-types.json +56 -58
- package/sed_ere/src/parser.c +28115 -37718
- package/src/grammar.json +655 -1101
- package/src/node-types.json +57 -49
- package/src/parser.c +31870 -41448
- package/tree-sitter.json +3 -3
- package/CMakeLists.txt +0 -121
- package/Makefile +0 -145
- package/bindings/c/tree-sitter-sed.pc.in +0 -10
- package/bindings/c/tree_sitter/tree-sitter-sed.h +0 -17
- package/test/binding.test.c +0 -9
package/Cargo.toml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
authors = ["konomanoasa"]
|
|
3
|
+
autoexamples = false
|
|
4
|
+
categories = ["parser-implementations", "parsing", "text-editors"]
|
|
5
|
+
description = "Tree-sitter grammars for POSIX sed."
|
|
6
|
+
edition = "2024"
|
|
7
|
+
keywords = ["incremental", "parsing", "tree-sitter", "sed"]
|
|
8
|
+
license = "MIT"
|
|
9
|
+
name = "tree-sitter-sed"
|
|
10
|
+
publish = false
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
repository = "https://github.com/konomanoasa/tree-sitter-sed"
|
|
13
|
+
version = "0.8.0"
|
|
14
|
+
|
|
15
|
+
build = "bindings/rust/build.rs"
|
|
16
|
+
include = [
|
|
17
|
+
"/LICENSE",
|
|
18
|
+
"/README.md",
|
|
19
|
+
"/bindings/rust/*.rs",
|
|
20
|
+
"/common/scanner.h",
|
|
21
|
+
"/queries/*.scm",
|
|
22
|
+
"/sed_ere/queries/*.scm",
|
|
23
|
+
"/sed_ere/src/node-types.json",
|
|
24
|
+
"/sed_ere/src/parser.c",
|
|
25
|
+
"/sed_ere/src/scanner.c",
|
|
26
|
+
"/sed_ere/src/tree_sitter/*.h",
|
|
27
|
+
"/src/node-types.json",
|
|
28
|
+
"/src/parser.c",
|
|
29
|
+
"/src/scanner.c",
|
|
30
|
+
"/src/tree_sitter/*.h",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[lib]
|
|
34
|
+
path = "bindings/rust/lib.rs"
|
|
35
|
+
|
|
36
|
+
[dependencies]
|
|
37
|
+
tree-sitter-language = "0.1"
|
|
38
|
+
|
|
39
|
+
[build-dependencies]
|
|
40
|
+
cc = "1.2"
|
|
41
|
+
|
|
42
|
+
[dev-dependencies]
|
|
43
|
+
tree-sitter = "0.27.0"
|
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ POSIX.1-2024 `sed`.
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
+
### npm
|
|
12
|
+
|
|
11
13
|
```sh
|
|
12
14
|
npm install tree-sitter-sed
|
|
13
15
|
```
|
|
@@ -16,10 +18,10 @@ npm install tree-sitter-sed
|
|
|
16
18
|
|
|
17
19
|
This repository contains the following two grammars.
|
|
18
20
|
|
|
19
|
-
| Grammar | Regexp |
|
|
20
|
-
| --------- | ------ |
|
|
21
|
-
| `sed` | BRE | `
|
|
22
|
-
| `sed_ere` | ERE | `
|
|
21
|
+
| Grammar | Regexp | Rust constant |
|
|
22
|
+
| --------- | ------ | -------------- |
|
|
23
|
+
| `sed` | BRE | `LANGUAGE` |
|
|
24
|
+
| `sed_ere` | ERE | `LANGUAGE_ERE` |
|
|
23
25
|
|
|
24
26
|
## Development
|
|
25
27
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
fn compile_parser(source_dir: &Path, library_name: &str, wasm_headers: Option<&Path>) {
|
|
4
|
+
let parser_path = source_dir.join("parser.c");
|
|
5
|
+
let scanner_path = source_dir.join("scanner.c");
|
|
6
|
+
let mut c_config = cc::Build::new();
|
|
7
|
+
c_config.std("c11").include(source_dir);
|
|
8
|
+
|
|
9
|
+
#[cfg(target_env = "msvc")]
|
|
10
|
+
c_config.flag("-utf-8");
|
|
11
|
+
|
|
12
|
+
if let Some(headers) = wasm_headers {
|
|
13
|
+
c_config.include(headers);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
c_config.file(&parser_path).file(&scanner_path);
|
|
17
|
+
c_config.compile(library_name);
|
|
18
|
+
|
|
19
|
+
println!("cargo:rerun-if-changed={}", parser_path.display());
|
|
20
|
+
println!("cargo:rerun-if-changed={}", scanner_path.display());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn main() {
|
|
24
|
+
let target = std::env::var("TARGET").expect("Cargo must provide TARGET");
|
|
25
|
+
let wasm_headers = (target == "wasm32-unknown-unknown").then(|| {
|
|
26
|
+
std::env::var_os("DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS")
|
|
27
|
+
.map(std::path::PathBuf::from)
|
|
28
|
+
.expect(
|
|
29
|
+
"tree-sitter-language must provide its headers when compiling for wasm32-unknown-unknown",
|
|
30
|
+
)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
compile_parser(Path::new("src"), "tree-sitter-sed", wasm_headers.as_deref());
|
|
34
|
+
compile_parser(
|
|
35
|
+
Path::new("sed_ere/src"),
|
|
36
|
+
"tree-sitter-sed-ere",
|
|
37
|
+
wasm_headers.as_deref(),
|
|
38
|
+
);
|
|
39
|
+
println!("cargo:rerun-if-changed=common/scanner.h");
|
|
40
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//! POSIX sed grammars for the Tree-sitter parsing library.
|
|
2
|
+
//!
|
|
3
|
+
//! [`LANGUAGE`] parses basic regular expressions, while [`LANGUAGE_ERE`] parses
|
|
4
|
+
//! extended regular expressions.
|
|
5
|
+
//!
|
|
6
|
+
//! ```
|
|
7
|
+
//! let mut parser = tree_sitter::Parser::new();
|
|
8
|
+
//! parser
|
|
9
|
+
//! .set_language(&tree_sitter_sed::LANGUAGE.into())
|
|
10
|
+
//! .expect("POSIX sed grammar must load");
|
|
11
|
+
//! let tree = parser.parse("p\n", None).expect("parser must return a tree");
|
|
12
|
+
//! assert!(!tree.root_node().has_error());
|
|
13
|
+
//! ```
|
|
14
|
+
|
|
15
|
+
use tree_sitter_language::LanguageFn;
|
|
16
|
+
|
|
17
|
+
unsafe extern "C" {
|
|
18
|
+
fn tree_sitter_sed() -> *const ();
|
|
19
|
+
fn tree_sitter_sed_ere() -> *const ();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// The Tree-sitter [`LanguageFn`] for POSIX sed with basic regular expressions.
|
|
23
|
+
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_sed) };
|
|
24
|
+
|
|
25
|
+
/// The Tree-sitter [`LanguageFn`] for POSIX sed with extended regular expressions.
|
|
26
|
+
pub const LANGUAGE_ERE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_sed_ere) };
|
|
27
|
+
|
|
28
|
+
/// The node type definitions for [`LANGUAGE`].
|
|
29
|
+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
30
|
+
|
|
31
|
+
/// The node type definitions for [`LANGUAGE_ERE`].
|
|
32
|
+
pub const NODE_TYPES_ERE: &str = include_str!("../../sed_ere/src/node-types.json");
|
|
33
|
+
|
|
34
|
+
/// The syntax highlighting query for [`LANGUAGE`].
|
|
35
|
+
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
|
36
|
+
|
|
37
|
+
/// The syntax highlighting query for [`LANGUAGE_ERE`].
|
|
38
|
+
pub const HIGHLIGHTS_QUERY_ERE: &str = include_str!("../../sed_ere/queries/highlights.scm");
|
|
39
|
+
|
|
40
|
+
#[cfg(test)]
|
|
41
|
+
mod tests {
|
|
42
|
+
fn assert_parses(language: tree_sitter_language::LanguageFn) {
|
|
43
|
+
let mut parser = tree_sitter::Parser::new();
|
|
44
|
+
parser
|
|
45
|
+
.set_language(&language.into())
|
|
46
|
+
.expect("generated grammar must be compatible with the Tree-sitter runtime");
|
|
47
|
+
let tree = parser
|
|
48
|
+
.parse("p\n", None)
|
|
49
|
+
.expect("parser must return a tree");
|
|
50
|
+
assert_eq!(tree.root_node().kind(), "script");
|
|
51
|
+
assert!(!tree.root_node().has_error());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[test]
|
|
55
|
+
fn sed_grammar_loads_and_parses() {
|
|
56
|
+
assert_parses(super::LANGUAGE);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[test]
|
|
60
|
+
fn sed_ere_grammar_loads_and_parses() {
|
|
61
|
+
assert_parses(super::LANGUAGE_ERE);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[test]
|
|
65
|
+
fn sed_and_sed_ere_are_distinct_grammars() {
|
|
66
|
+
let sed = tree_sitter::Language::new(super::LANGUAGE);
|
|
67
|
+
let sed_ere = tree_sitter::Language::new(super::LANGUAGE_ERE);
|
|
68
|
+
assert_ne!(sed, sed_ere);
|
|
69
|
+
}
|
|
70
|
+
}
|