@konomanoasa/tree-sitter-toml 0.1.0 → 0.2.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 ADDED
@@ -0,0 +1,23 @@
1
+ [package]
2
+ name = "tree-sitter-toml"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ build = "bindings/rust/build.rs"
6
+ links = "tree-sitter-toml"
7
+ publish = false
8
+
9
+ [lib]
10
+ path = "bindings/rust/lib.rs"
11
+
12
+ [[test]]
13
+ name = "bindings"
14
+ path = "test/bindings.test.rs"
15
+
16
+ [dependencies]
17
+ tree-sitter-language = "0.1.8"
18
+
19
+ [dev-dependencies]
20
+ tree-sitter = "0.27.0"
21
+
22
+ [build-dependencies]
23
+ cc = "1.4"
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm](https://img.shields.io/npm/v/@konomanoasa/tree-sitter-toml)](https://www.npmjs.com/package/@konomanoasa/tree-sitter-toml)
5
5
 
6
6
  [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
7
- TOML 1.1.0.
7
+ Tom's Obvious Minimal Language 1.1.0.
8
8
 
9
9
  ## Installation
10
10
 
@@ -12,11 +12,20 @@ TOML 1.1.0.
12
12
  npm install @konomanoasa/tree-sitter-toml
13
13
  ```
14
14
 
15
+ ## Grammar
16
+
17
+ | Grammar | Description | Rust constant |
18
+ | --- | --- | --- |
19
+ | `toml` | TOML 1.1.0 | `LANGUAGE` |
20
+
15
21
  ## Development
16
22
 
23
+ Development requires Node.js 24.2.0 or later.
24
+
17
25
  ```sh
18
26
  npm install
19
- npm run parse -- script.toml
27
+ npm run build
28
+ npm test
20
29
  ```
21
30
 
22
31
  ## Specifications
@@ -0,0 +1,23 @@
1
+ use std::{env, path::Path};
2
+
3
+ fn main() {
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
+ }
17
+
18
+ println!("cargo::rerun-if-changed=src");
19
+ build
20
+ .include("src")
21
+ .files(["src/parser.c", "src/scanner.c"])
22
+ .compile("tree-sitter-toml");
23
+ }
@@ -0,0 +1,12 @@
1
+ use tree_sitter_language::LanguageFn;
2
+
3
+ unsafe extern "C" {
4
+ fn tree_sitter_toml() -> *const ();
5
+ }
6
+
7
+ pub const LANGUAGE: LanguageFn =
8
+ unsafe { LanguageFn::from_raw(tree_sitter_toml) };
9
+
10
+ pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
11
+
12
+ pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
package/package.json CHANGED
@@ -1,27 +1,31 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-toml",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Tree-sitter grammar for TOML.",
6
6
  "license": "MIT",
7
7
  "repository": "git+https://github.com/konomanoasa/tree-sitter-toml.git",
8
8
  "files": [
9
+ "Cargo.toml",
10
+ "bindings/rust/*.rs",
9
11
  "grammar.js",
10
12
  "queries/*.scm",
11
13
  "src/*.c",
12
14
  "src/*.json",
13
15
  "src/tree_sitter/*.h",
16
+ "test/bindings.test.rs",
14
17
  "tree-sitter.json"
15
18
  ],
16
19
  "publishConfig": {
17
20
  "access": "public"
18
21
  },
19
22
  "scripts": {
23
+ "build": "npm run tree-sitter -- build-all",
20
24
  "check": "biome check . && node scripts/check-c.js && node scripts/check-generated.js && npm test",
21
25
  "format": "biome check --write . && node scripts/check-c.js --write",
22
26
  "generate": "npm run tree-sitter -- generate-all",
23
- "parse": "npm run tree-sitter -- parse --scope source.toml",
24
27
  "test": "npm run tree-sitter -- test-corpus --rebuild && node --test --test-concurrency=1 \"test/*.test.js\"",
28
+ "test:bindings": "cargo test --locked",
25
29
  "test:fuzz": "node --test --test-name-pattern=\"fixed-seed generated histories\" test/incremental.test.js",
26
30
  "test:fuzz:corpus": "npm run tree-sitter -- fuzz-all --iterations 100 --edits 5",
27
31
  "test:highlights": "node --test test/highlight.test.js",
package/src/parser.c CHANGED
@@ -8362,7 +8362,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_toml(void) {
8362
8362
  .max_reserved_word_set_size = 0,
8363
8363
  .metadata = {
8364
8364
  .major_version = 0,
8365
- .minor_version = 1,
8365
+ .minor_version = 2,
8366
8366
  .patch_version = 0,
8367
8367
  },
8368
8368
  };
@@ -0,0 +1,29 @@
1
+ use tree_sitter::{Parser, Query};
2
+ use tree_sitter_toml as grammar;
3
+
4
+ #[test]
5
+ fn parses_valid_source() {
6
+ let source = "answer = 42\n";
7
+ let mut parser = Parser::new();
8
+ parser.set_language(&grammar::LANGUAGE.into()).unwrap();
9
+ let tree = parser.parse(source, None).unwrap();
10
+ let root = tree.root_node();
11
+ assert_eq!(root.kind(), "toml");
12
+ assert_eq!(root.byte_range(), 0..source.len());
13
+ assert!(!root.has_error());
14
+ }
15
+
16
+ #[test]
17
+ fn linked_scanner_preserves_quotes_in_multiline_strings() {
18
+ let language = grammar::LANGUAGE.into();
19
+ let mut parser = Parser::new();
20
+ parser.set_language(&language).unwrap();
21
+ for source in ["a = \"\"\"one\"two\"\"\"\n", "a = '''one'two'''\n"] {
22
+ let tree = parser.parse(source, None).unwrap();
23
+ let root = tree.root_node();
24
+ assert_eq!(root.kind(), "toml");
25
+ assert_eq!(root.byte_range(), 0..source.len());
26
+ assert!(!root.has_error(), "{source}");
27
+ }
28
+ Query::new(&language, grammar::HIGHLIGHTS_QUERY).unwrap();
29
+ }
package/tree-sitter.json CHANGED
@@ -12,7 +12,7 @@
12
12
  }
13
13
  ],
14
14
  "metadata": {
15
- "version": "0.1.0",
15
+ "version": "0.2.0",
16
16
  "license": "MIT",
17
17
  "description": "Tree-sitter grammar for TOML.",
18
18
  "links": {
@@ -24,7 +24,7 @@
24
24
  "go": false,
25
25
  "node": false,
26
26
  "python": false,
27
- "rust": false,
27
+ "rust": true,
28
28
  "swift": false
29
29
  }
30
30
  }