tree-sitter-kdl 1.0.1 → 1.0.2
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/.gitattributes +2 -1
- package/Cargo.toml +7 -5
- package/LICENSE +18 -4
- package/Package.swift +38 -0
- package/README.md +1 -1
- package/bindings/node/binding.cc +7 -5
- package/bindings/node/index.js +4 -4
- package/bindings/rust/README.md +36 -0
- package/bindings/rust/build.rs +0 -19
- package/bindings/rust/lib.rs +22 -10
- package/bindings/swift/kdl.h +16 -0
- package/grammar.js +2 -3
- package/package.json +1 -1
- package/examples/01-basic.kdl +0 -1
- package/examples/02-multiple-values.kdl +0 -1
- package/examples/03-properties.kdl +0 -1
- package/examples/04-child-nodes.kdl +0 -6
- package/examples/05-node-terminators.kdl +0 -1
- package/examples/06-string-formats.kdl +0 -2
- package/examples/07-multiline-string.kdl +0 -3
- package/examples/08-raw-string.kdl +0 -1
- package/examples/09-number.kdl +0 -1
- package/examples/10-number-forms.kdl +0 -3
- package/examples/11-number-with-underscores.kdl +0 -1
- package/examples/12-comments.kdl +0 -11
- package/examples/13-slashdash-comments.kdl +0 -11
- package/examples/14-type-annotations.kdl +0 -4
- package/examples/15-rich-example.kdl +0 -21
- package/script/known_failures.txt +0 -0
- package/script/parse-examples +0 -40
- package/test/corpus/node.txt +0 -2784
package/.gitattributes
CHANGED
package/Cargo.toml
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "tree-sitter-kdl"
|
|
3
|
-
description = "
|
|
4
|
-
version = "1.0.
|
|
3
|
+
description = "KDL grammar for tree-sitter"
|
|
4
|
+
version = "1.0.2"
|
|
5
5
|
authors = [
|
|
6
6
|
"Amaan Qureshi <amaanq12@gmail.com>",
|
|
7
7
|
"Andrew Hlynskyi <ahlincq@gmail.com>",
|
|
8
8
|
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
readme = "bindings/rust/README.md"
|
|
9
11
|
keywords = ["incremental", "parsing", "kdl"]
|
|
10
12
|
categories = ["parsing", "text-editors"]
|
|
11
|
-
repository = "https://github.com/
|
|
12
|
-
edition = "
|
|
13
|
-
|
|
13
|
+
repository = "https://github.com/amaanq/tree-sitter-kdl"
|
|
14
|
+
edition = "2021"
|
|
15
|
+
autoexamples = false
|
|
14
16
|
|
|
15
17
|
build = "bindings/rust/build.rs"
|
|
16
18
|
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
package/LICENSE
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>, Andrew Hlynskyi <ahlincq@gmail.com>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// swift-tools-version:5.3
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "TreeSitterKDL",
|
|
6
|
+
platforms: [.macOS(.v10_13), .iOS(.v11)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(name: "TreeSitterKDL", targets: ["TreeSitterKDL"]),
|
|
9
|
+
],
|
|
10
|
+
dependencies: [],
|
|
11
|
+
targets: [
|
|
12
|
+
.target(name: "TreeSitterKDL",
|
|
13
|
+
path: ".",
|
|
14
|
+
exclude: [
|
|
15
|
+
"binding.gyp",
|
|
16
|
+
"bindings",
|
|
17
|
+
"Cargo.toml",
|
|
18
|
+
"test",
|
|
19
|
+
"examples",
|
|
20
|
+
"grammar.js",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"package.json",
|
|
23
|
+
"README.md",
|
|
24
|
+
"script",
|
|
25
|
+
"src/grammar.json",
|
|
26
|
+
"src/node-types.json",
|
|
27
|
+
],
|
|
28
|
+
sources: [
|
|
29
|
+
"src/parser.c",
|
|
30
|
+
"src/scanner.c",
|
|
31
|
+
],
|
|
32
|
+
resources: [
|
|
33
|
+
.copy("queries")
|
|
34
|
+
],
|
|
35
|
+
publicHeadersPath: "bindings/swift",
|
|
36
|
+
cSettings: [.headerSearchPath("src")])
|
|
37
|
+
]
|
|
38
|
+
)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tree-sitter-kdl
|
|
2
2
|
|
|
3
|
-
[](https://github.com/amaanq/tree-sitter-kdl/actions/workflows/ci.yml)
|
|
4
4
|
[](https://discord.gg/w7nTvsVJhm)
|
|
5
5
|
|
|
6
6
|
KDL grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
package/bindings/node/binding.cc
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
#include "nan.h"
|
|
1
2
|
#include "tree_sitter/parser.h"
|
|
2
3
|
#include <node.h>
|
|
3
|
-
#include "nan.h"
|
|
4
4
|
|
|
5
5
|
using namespace v8;
|
|
6
6
|
|
|
7
|
-
extern "C" TSLanguage *
|
|
7
|
+
extern "C" TSLanguage *tree_sitter_kdl();
|
|
8
8
|
|
|
9
9
|
namespace {
|
|
10
10
|
|
|
@@ -16,13 +16,15 @@ void Init(Local<Object> exports, Local<Object> module) {
|
|
|
16
16
|
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
17
17
|
|
|
18
18
|
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
|
19
|
-
Local<Object> instance =
|
|
19
|
+
Local<Object> instance =
|
|
20
|
+
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
|
20
21
|
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_kdl());
|
|
21
22
|
|
|
22
|
-
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
|
|
23
|
+
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
|
|
24
|
+
Nan::New("kdl").ToLocalChecked());
|
|
23
25
|
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
NODE_MODULE(tree_sitter_kdl_binding, Init)
|
|
27
29
|
|
|
28
|
-
}
|
|
30
|
+
} // namespace
|
package/bindings/node/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
try {
|
|
2
|
-
module.exports = require(
|
|
2
|
+
module.exports = require('../../build/Release/tree_sitter_kdl_binding');
|
|
3
3
|
} catch (error1) {
|
|
4
4
|
if (error1.code !== 'MODULE_NOT_FOUND') {
|
|
5
5
|
throw error1;
|
|
6
6
|
}
|
|
7
7
|
try {
|
|
8
|
-
module.exports = require(
|
|
8
|
+
module.exports = require('../../build/Debug/tree_sitter_kdl_binding');
|
|
9
9
|
} catch (error2) {
|
|
10
10
|
if (error2.code !== 'MODULE_NOT_FOUND') {
|
|
11
11
|
throw error2;
|
|
12
12
|
}
|
|
13
|
-
throw error1
|
|
13
|
+
throw error1;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
|
-
module.exports.nodeTypeInfo = require(
|
|
18
|
+
module.exports.nodeTypeInfo = require('../../src/node-types.json');
|
|
19
19
|
} catch (_) {}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# tree-sitter-kdl
|
|
2
|
+
|
|
3
|
+
This crate provides a KDL grammar for the [tree-sitter][] parsing library. To
|
|
4
|
+
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
|
|
5
|
+
file. (Note that you will probably also need to depend on the
|
|
6
|
+
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
|
|
7
|
+
way.)
|
|
8
|
+
|
|
9
|
+
```toml
|
|
10
|
+
[dependencies]
|
|
11
|
+
tree-sitter = "~0.20.3"
|
|
12
|
+
tree-sitter-kdl = "1.0.2"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Typically, you will use the [language][language func] function to add this
|
|
16
|
+
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
|
|
17
|
+
|
|
18
|
+
```rust
|
|
19
|
+
let code = r#"
|
|
20
|
+
fn double(x: i32) -> i32 {
|
|
21
|
+
x * 2
|
|
22
|
+
}
|
|
23
|
+
"#;
|
|
24
|
+
let mut parser = Parser::new();
|
|
25
|
+
parser.set_language(tree_sitter_kdl::language()).expect("Error loading KDL grammar");
|
|
26
|
+
let parsed = parser.parse(code, None);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
If you have any questions, please reach out to us in the [tree-sitter
|
|
30
|
+
discussions] page.
|
|
31
|
+
|
|
32
|
+
[language func]: https://docs.rs/tree-sitter-kdl/*/tree_sitter_kdl/fn.language.html
|
|
33
|
+
[parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
34
|
+
[tree-sitter]: https://tree-sitter.github.io/
|
|
35
|
+
[tree-sitter crate]: https://crates.io/crates/tree-sitter
|
|
36
|
+
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions
|
package/bindings/rust/build.rs
CHANGED
|
@@ -10,29 +10,10 @@ fn main() {
|
|
|
10
10
|
let parser_path = src_dir.join("parser.c");
|
|
11
11
|
c_config.file(&parser_path);
|
|
12
12
|
|
|
13
|
-
// If your language uses an external scanner written in C,
|
|
14
|
-
// then include this block of code:
|
|
15
|
-
|
|
16
13
|
let scanner_path = src_dir.join("scanner.c");
|
|
17
14
|
c_config.file(&scanner_path);
|
|
18
15
|
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
19
16
|
|
|
20
17
|
c_config.compile("parser");
|
|
21
18
|
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
|
22
|
-
|
|
23
|
-
// If your language uses an external scanner written in C++,
|
|
24
|
-
// then include this block of code:
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
let mut cpp_config = cc::Build::new();
|
|
28
|
-
cpp_config.cpp(true);
|
|
29
|
-
cpp_config.include(&src_dir);
|
|
30
|
-
cpp_config
|
|
31
|
-
.flag_if_supported("-Wno-unused-parameter")
|
|
32
|
-
.flag_if_supported("-Wno-unused-but-set-variable");
|
|
33
|
-
let scanner_path = src_dir.join("scanner.cc");
|
|
34
|
-
cpp_config.file(&scanner_path);
|
|
35
|
-
cpp_config.compile("scanner");
|
|
36
|
-
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
37
|
-
*/
|
|
38
19
|
}
|
package/bindings/rust/lib.rs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// ------------------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright © 2023, Amaan Qureshi <amaanq12@gmail.com>, Andrew Hlynskyi <ahlincq@gmail.com>
|
|
3
|
+
// See the LICENSE file in this repo for license details.
|
|
4
|
+
// ------------------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
//! This crate provides KDL language support for the [tree-sitter][] parsing library.
|
|
2
7
|
//!
|
|
3
8
|
//! Typically, you will use the [language][language func] function to add this language to a
|
|
4
9
|
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
@@ -28,18 +33,25 @@ pub fn language() -> Language {
|
|
|
28
33
|
unsafe { tree_sitter_kdl() }
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
/// The
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
/// The source of the Rust tree-sitter grammar description.
|
|
37
|
+
pub const GRAMMAR: &str = include_str!("../../grammar.js");
|
|
38
|
+
|
|
39
|
+
/// The syntax highlighting query for this language.
|
|
40
|
+
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
/// The injection query for this language.
|
|
43
|
+
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
|
|
44
|
+
|
|
45
|
+
/// The symbol tagging query for this language.
|
|
46
|
+
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
|
|
37
47
|
|
|
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
48
|
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
|
42
49
|
|
|
50
|
+
/// The content of the [`node-types.json`][] file for this grammar.
|
|
51
|
+
///
|
|
52
|
+
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
53
|
+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
54
|
+
|
|
43
55
|
#[cfg(test)]
|
|
44
56
|
mod tests {
|
|
45
57
|
#[test]
|
|
@@ -47,6 +59,6 @@ mod tests {
|
|
|
47
59
|
let mut parser = tree_sitter::Parser::new();
|
|
48
60
|
parser
|
|
49
61
|
.set_language(super::language())
|
|
50
|
-
.expect("Error loading
|
|
62
|
+
.expect("Error loading KDL grammar");
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef TREE_SITTER_KDL_H_
|
|
2
|
+
#define TREE_SITTER_KDL_H_
|
|
3
|
+
|
|
4
|
+
typedef struct TSLanguage TSLanguage;
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
extern TSLanguage *tree_sitter_kdl();
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
}
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#endif // TREE_SITTER_KDL_H_
|
package/grammar.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* @file KDL grammar for tree-sitter
|
|
3
3
|
* @author Amaan Qureshi <amaanq12@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
|
-
* @see {@link https://
|
|
6
|
-
* @see {@link https://
|
|
7
|
-
* @see {@link https://www.filterblade.xyz/|filter generator}
|
|
5
|
+
* @see {@link https://kdl.dev|official website}
|
|
6
|
+
* @see {@link https://github.com/kdl-org/kdl/blob/main/SPEC.md|official syntax spec}
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
// deno-lint-ignore-file no-control-regex
|
package/package.json
CHANGED
package/examples/01-basic.kdl
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
title "Hello, World"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bookmarks 12 15 188 1234
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
author "Alex Monad" email="alex@example.com" active=true
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node1; node2; node3;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
other-raw r#"hello"world"#
|
package/examples/09-number.kdl
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
num 1.234e-42
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bignum 1_000_000
|
package/examples/12-comments.kdl
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Nodes can be separated into multiple lines
|
|
2
|
-
title \
|
|
3
|
-
"Some title"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Files must be utf8 encoded!
|
|
7
|
-
smile "😁"
|
|
8
|
-
|
|
9
|
-
// Instead of anonymous nodes, nodes and properties can be wrapped
|
|
10
|
-
// in "" for arbitrary node names.
|
|
11
|
-
"!@#$@$%Q#$%~@!40" "1.2.3" "!!!!!"=true
|
|
12
|
-
|
|
13
|
-
// The following is a legal bare identifier:
|
|
14
|
-
foo123~!@#$%^&*.:'|?+ "weeee"
|
|
15
|
-
|
|
16
|
-
// And you can also use unicode!
|
|
17
|
-
ノード お名前="☜(゚ヮ゚☜)"
|
|
18
|
-
|
|
19
|
-
// kdl specifically allows properties and values to be
|
|
20
|
-
// interspersed with each other, much like CLI commands.
|
|
21
|
-
foo bar=true "baz" quux=false 1 2 3
|
|
File without changes
|
package/script/parse-examples
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
cd "$(dirname "$0")/.."
|
|
6
|
-
|
|
7
|
-
function checkout() {
|
|
8
|
-
repo=$1; url=$2; sha=$3
|
|
9
|
-
|
|
10
|
-
if [ ! -d "$repo" ]; then
|
|
11
|
-
git clone "https://github.com/$url" "$repo"
|
|
12
|
-
fi
|
|
13
|
-
|
|
14
|
-
pushd "$repo"
|
|
15
|
-
git fetch && git reset --hard "$sha"
|
|
16
|
-
popd
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
checkout examples/kdl kdl-org/kdl 6feeccc491808fe0b5425a18aa7ab4a8ac435e55
|
|
20
|
-
checkout examples/kdl-rs kdl-org/kdl-rs 8c028e5ea189470f07c5c848ab778f3d63ba89ab
|
|
21
|
-
checkout examples/kdl-js kdl-org/kdljs bb874a595e6f712950795ecaad62f24fd945f03d
|
|
22
|
-
checkout examples/kdl-php kdl-org/kdl-php 390fdc5ab8e2749feb01a113e8feb028de0861b3
|
|
23
|
-
|
|
24
|
-
known_failures="$(cat script/known_failures.txt)"
|
|
25
|
-
|
|
26
|
-
# Remove input directories
|
|
27
|
-
find examples -type d -name input -exec rm -rf {} +
|
|
28
|
-
|
|
29
|
-
tree-sitter parse -q \
|
|
30
|
-
'examples/**/*.kdl' \
|
|
31
|
-
"$(for file in $known_failures; do echo "!${file}"; done)"
|
|
32
|
-
|
|
33
|
-
example_count=$(find examples -name '*.kdl' | wc -l)
|
|
34
|
-
failure_count=$(wc -w <<< "$known_failures")
|
|
35
|
-
success_count=$(( example_count - failure_count ))
|
|
36
|
-
success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
|
|
37
|
-
|
|
38
|
-
printf \
|
|
39
|
-
"Successfully parsed %d of %d example files (%.1f%%)\n" \
|
|
40
|
-
$success_count "$example_count" "$success_percent"
|