tree-sitter-kdl 1.0.0 → 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 +4 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/fuzz.yml +1 -1
- package/.github/workflows/{build.yml → publish.yml} +1 -1
- package/Cargo.toml +11 -6
- package/LICENSE +21 -0
- package/Package.swift +38 -0
- package/README.md +3 -0
- package/binding.gyp +0 -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 +47 -40
- package/package.json +27 -13
- package/queries/folds.scm +6 -1
- package/queries/highlights.scm +1 -1
- package/queries/indents.scm +7 -0
- package/queries/injections.scm +4 -0
- package/queries/locals.scm +10 -0
- 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/.github/workflows/ci.yml
CHANGED
package/Cargo.toml
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "tree-sitter-kdl"
|
|
3
|
-
description = "
|
|
4
|
-
version = "
|
|
5
|
-
authors = [
|
|
3
|
+
description = "KDL grammar for tree-sitter"
|
|
4
|
+
version = "1.0.2"
|
|
5
|
+
authors = [
|
|
6
|
+
"Amaan Qureshi <amaanq12@gmail.com>",
|
|
7
|
+
"Andrew Hlynskyi <ahlincq@gmail.com>",
|
|
8
|
+
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
readme = "bindings/rust/README.md"
|
|
6
11
|
keywords = ["incremental", "parsing", "kdl"]
|
|
7
12
|
categories = ["parsing", "text-editors"]
|
|
8
|
-
repository = "https://github.com/
|
|
9
|
-
edition = "
|
|
10
|
-
|
|
13
|
+
repository = "https://github.com/amaanq/tree-sitter-kdl"
|
|
14
|
+
edition = "2021"
|
|
15
|
+
autoexamples = false
|
|
11
16
|
|
|
12
17
|
build = "bindings/rust/build.rs"
|
|
13
18
|
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>, Andrew Hlynskyi <ahlincq@gmail.com>
|
|
4
|
+
|
|
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:
|
|
11
|
+
|
|
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,5 +1,8 @@
|
|
|
1
1
|
# tree-sitter-kdl
|
|
2
2
|
|
|
3
|
+
[](https://github.com/amaanq/tree-sitter-kdl/actions/workflows/ci.yml)
|
|
4
|
+
[](https://discord.gg/w7nTvsVJhm)
|
|
5
|
+
|
|
3
6
|
KDL grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
|
4
7
|
|
|
5
8
|
Adapted from the [official spec](https://github.com/kdl-org/kdl/blob/main/SPEC.md)
|
package/binding.gyp
CHANGED
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
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file KDL grammar for tree-sitter
|
|
3
|
+
* @author Amaan Qureshi <amaanq12@gmail.com>
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @see {@link https://kdl.dev|official website}
|
|
6
|
+
* @see {@link https://github.com/kdl-org/kdl/blob/main/SPEC.md|official syntax spec}
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
// deno-lint-ignore-file no-control-regex
|
|
10
|
+
/* eslint-disable arrow-parens */
|
|
2
11
|
/* eslint-disable camelcase */
|
|
3
12
|
/* eslint-disable-next-line spaced-comment */
|
|
4
13
|
/// <reference types="tree-sitter-cli/dsl" />
|
|
@@ -51,21 +60,21 @@ const ANNOTATION_BUILTINS = [
|
|
|
51
60
|
module.exports = grammar({
|
|
52
61
|
name: 'kdl',
|
|
53
62
|
|
|
54
|
-
conflicts:
|
|
63
|
+
conflicts: $ => [
|
|
55
64
|
[$.document],
|
|
56
65
|
[$._node_space],
|
|
57
66
|
[$.node_children],
|
|
58
67
|
],
|
|
59
68
|
|
|
60
|
-
extras:
|
|
69
|
+
extras: $ => [$.multi_line_comment],
|
|
61
70
|
|
|
62
|
-
externals:
|
|
71
|
+
externals: $ => [$._eof],
|
|
63
72
|
|
|
64
|
-
word:
|
|
73
|
+
word: $ => $._normal_bare_identifier,
|
|
65
74
|
|
|
66
75
|
rules: {
|
|
67
76
|
// nodes := linespace* (node nodes?)? linespace*
|
|
68
|
-
document:
|
|
77
|
+
document: $ =>
|
|
69
78
|
seq(
|
|
70
79
|
repeat($._linespace),
|
|
71
80
|
optional(seq(
|
|
@@ -79,7 +88,7 @@ module.exports = grammar({
|
|
|
79
88
|
),
|
|
80
89
|
|
|
81
90
|
// node := ('/-' node-space*)? type? identifier (node-space+ node-prop-or-arg)* (node-space* node-children ws*)? node-space* node-terminator
|
|
82
|
-
node:
|
|
91
|
+
node: $ => prec(PREC.node,
|
|
83
92
|
seq(
|
|
84
93
|
alias(optional(seq('/-', repeat($._node_space))), $.node_comment),
|
|
85
94
|
optional($.type),
|
|
@@ -92,16 +101,16 @@ module.exports = grammar({
|
|
|
92
101
|
),
|
|
93
102
|
|
|
94
103
|
// node-prop-or-arg (field) := ('/-' node-space*)? (prop | value)
|
|
95
|
-
// _node_prop_or_arg:
|
|
104
|
+
// _node_prop_or_arg: $ =>
|
|
96
105
|
// seq(
|
|
97
106
|
// alias(optional(seq('/-', repeat($._node_space))), $.node_prop_or_arg_slash_dash),
|
|
98
107
|
// field('node_prop_or_arg', choice($.prop, $.value)),
|
|
99
108
|
// ),
|
|
100
|
-
node_field:
|
|
101
|
-
_node_field_comment:
|
|
102
|
-
_node_field:
|
|
109
|
+
node_field: $ => choice($._node_field_comment, $._node_field),
|
|
110
|
+
_node_field_comment: $ => alias(seq('/-', repeat($._node_space), $._node_field), $.node_field_comment),
|
|
111
|
+
_node_field: $ => choice($.prop, $.value),
|
|
103
112
|
// node-children := ('/-' node-space*)? '{' nodes '}'
|
|
104
|
-
node_children:
|
|
113
|
+
node_children: $ =>
|
|
105
114
|
seq(
|
|
106
115
|
optional(seq(alias('/-', $.node_children_comment), repeat($._node_space))),
|
|
107
116
|
'{',
|
|
@@ -113,26 +122,25 @@ module.exports = grammar({
|
|
|
113
122
|
'}',
|
|
114
123
|
),
|
|
115
124
|
// node-space := ws* escline ws* | ws+
|
|
116
|
-
_node_space:
|
|
125
|
+
_node_space: $ =>
|
|
117
126
|
choice(
|
|
118
127
|
seq(repeat($._ws), $._escline, repeat($._ws)),
|
|
119
128
|
repeat1($._ws),
|
|
120
129
|
),
|
|
121
130
|
// node-terminator := single-line-comment | newline | ';' | eof
|
|
122
|
-
_node_terminator:
|
|
131
|
+
_node_terminator: $ =>
|
|
123
132
|
choice($.single_line_comment, $._newline, ';', $._eof),
|
|
124
133
|
|
|
125
|
-
|
|
126
134
|
// identifier := string | bare-identifier
|
|
127
|
-
identifier:
|
|
135
|
+
identifier: $ => choice($.string, $._bare_identifier),
|
|
128
136
|
// bare-identifier := ((identifier-char - digit - sign) identifier-char* | sign ((identifier-char - digit) identifier-char*)?) - keyword
|
|
129
|
-
_bare_identifier:
|
|
137
|
+
_bare_identifier: $ =>
|
|
130
138
|
choice(
|
|
131
139
|
$._normal_bare_identifier,
|
|
132
140
|
seq($._sign, optional(seq($.__identifier_char_no_digit, repeat($._identifier_char)))),
|
|
133
141
|
),
|
|
134
142
|
|
|
135
|
-
// _normal_bare_identifier:
|
|
143
|
+
// _normal_bare_identifier: $ => $.__identifier_char_no_digit_sign,
|
|
136
144
|
_normal_bare_identifier: () => token(
|
|
137
145
|
seq(
|
|
138
146
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}_~!@#\$%\^&\*.:'\|\?&&[^\s\d\/(){}<>;\[\]=,"]]/,
|
|
@@ -155,23 +163,23 @@ module.exports = grammar({
|
|
|
155
163
|
),
|
|
156
164
|
|
|
157
165
|
// keyword := boolean | 'null'
|
|
158
|
-
keyword:
|
|
166
|
+
keyword: $ => choice($.boolean, 'null'),
|
|
159
167
|
// type annotations
|
|
160
168
|
annotation_type: () => choice(...ANNOTATION_BUILTINS),
|
|
161
169
|
// prop := identifier '=' value
|
|
162
|
-
prop:
|
|
170
|
+
prop: $ => seq($.identifier, '=', $.value),
|
|
163
171
|
// value := type? (string | number | keyword)
|
|
164
|
-
value:
|
|
172
|
+
value: $ => seq(optional($.type), choice($.string, $.number, $.keyword)),
|
|
165
173
|
// type := '(' identifier ')'
|
|
166
|
-
type:
|
|
174
|
+
type: $ => seq('(', choice($.identifier, $.annotation_type), ')'),
|
|
167
175
|
|
|
168
176
|
// String
|
|
169
177
|
// string := raw-string | escaped-string
|
|
170
|
-
string:
|
|
178
|
+
string: $ => choice($._raw_string, $._escaped_string),
|
|
171
179
|
// escaped-string := '"' character* '"'
|
|
172
|
-
_escaped_string:
|
|
180
|
+
_escaped_string: $ => seq('"', alias(repeat(choice($.escape, /[^"]/)), $.string_fragment), '"'),
|
|
173
181
|
// character := '\' escape | [^\"]
|
|
174
|
-
_character:
|
|
182
|
+
_character: $ => choice($.escape, /[^"]/),
|
|
175
183
|
// escape := ["\\/bfnrt] | 'u{' hex-digit{1, 6} '}'
|
|
176
184
|
escape: () =>
|
|
177
185
|
token.immediate(/\\\\|\\"|\\\/|\\b|\\f|\\n|\\r|\\t|\\u\{[0-9a-fA-F]{1,6}\}/),
|
|
@@ -179,9 +187,9 @@ module.exports = grammar({
|
|
|
179
187
|
_hex_digit: () => /[0-9a-fA-F]/,
|
|
180
188
|
|
|
181
189
|
// // raw-string := 'r' raw-string-hash
|
|
182
|
-
// raw_string:
|
|
190
|
+
// raw_string: $ => seq('r', $._raw_string_hash),
|
|
183
191
|
// // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
|
|
184
|
-
// _raw_string_hash:
|
|
192
|
+
// _raw_string_hash: $ => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
|
|
185
193
|
// // raw-string-quotes := '"' .* '"'
|
|
186
194
|
// _raw_string_quotes: () => seq('"', /.*/, '"'),
|
|
187
195
|
_raw_string: () =>
|
|
@@ -195,12 +203,11 @@ module.exports = grammar({
|
|
|
195
203
|
),
|
|
196
204
|
),
|
|
197
205
|
|
|
198
|
-
|
|
199
206
|
// number := decimal | hex | octal | binary
|
|
200
|
-
number:
|
|
207
|
+
number: $ => choice($._decimal, $._hex, $._octal, $._binary),
|
|
201
208
|
|
|
202
209
|
// decimal := sign? integer ('.' integer)? exponent?
|
|
203
|
-
_decimal:
|
|
210
|
+
_decimal: $ =>
|
|
204
211
|
seq(
|
|
205
212
|
optional($._sign),
|
|
206
213
|
$._integer,
|
|
@@ -209,29 +216,29 @@ module.exports = grammar({
|
|
|
209
216
|
),
|
|
210
217
|
|
|
211
218
|
// exponent := ('e' | 'E') sign? integer
|
|
212
|
-
_exponent:
|
|
219
|
+
_exponent: $ => seq(choice('e', 'E'), optional($._sign), $._integer),
|
|
213
220
|
// integer := digit (digit | '_')*
|
|
214
|
-
_integer:
|
|
221
|
+
_integer: $ => seq($._digit, repeat(choice($._digit, '_'))),
|
|
215
222
|
// digit := [0-9]
|
|
216
223
|
_digit: () => /[0-9]/,
|
|
217
224
|
// sign := '+' | '-'
|
|
218
225
|
_sign: () => choice('+', '-'),
|
|
219
226
|
|
|
220
227
|
// hex := sign? '0x' hex-digit (hex-digit | '_')*
|
|
221
|
-
_hex:
|
|
228
|
+
_hex: $ => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
|
|
222
229
|
// octal := sign? '0o' [0-7] [0-7_]*
|
|
223
|
-
_octal:
|
|
230
|
+
_octal: $ => seq(optional($._sign), '0o', /[0-7]/, repeat(choice(/[0-7]/, '_'))),
|
|
224
231
|
// binary := sign? '0b' ('0' | '1') ('0' | '1' | '_')*
|
|
225
|
-
_binary:
|
|
232
|
+
_binary: $ => seq(optional($._sign), '0b', choice('0', '1'), repeat(choice('0', '1', '_'))),
|
|
226
233
|
|
|
227
234
|
// boolean := 'true' | 'false'
|
|
228
235
|
boolean: () => choice('true', 'false'),
|
|
229
236
|
|
|
230
237
|
// escline := '\\' ws* (single-line-comment | newline)
|
|
231
|
-
_escline:
|
|
238
|
+
_escline: $ => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
|
|
232
239
|
|
|
233
240
|
// linespace := newline | ws | single-line-comment
|
|
234
|
-
_linespace:
|
|
241
|
+
_linespace: $ => choice($._newline, $._ws, $.single_line_comment),
|
|
235
242
|
|
|
236
243
|
// newline := See Table (All line-break white_space)
|
|
237
244
|
// Newline
|
|
@@ -251,7 +258,7 @@ module.exports = grammar({
|
|
|
251
258
|
_newline: () => choice(/\r'/, /\n/, /\r\n/, /\u0085/, /\u000C/, /\u2028/, /\u2029/),
|
|
252
259
|
|
|
253
260
|
// ws := bom | unicode-space | multi-line-comment
|
|
254
|
-
_ws:
|
|
261
|
+
_ws: $ => choice($._bom, $._unicode_space, $.multi_line_comment),
|
|
255
262
|
|
|
256
263
|
// bom := '\u{FEFF}'
|
|
257
264
|
_bom: () => /\u{FEFF}/,
|
|
@@ -285,17 +292,17 @@ module.exports = grammar({
|
|
|
285
292
|
/[\u0009\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/,
|
|
286
293
|
|
|
287
294
|
// single-line-comment := '//' ^newline+ (newline | eof)
|
|
288
|
-
single_line_comment:
|
|
295
|
+
single_line_comment: $ =>
|
|
289
296
|
seq(
|
|
290
297
|
'//',
|
|
291
298
|
repeat1(/[^\r\n\u0085\u000C\u2028\u2029]/),
|
|
292
299
|
choice($._newline, $._eof),
|
|
293
300
|
),
|
|
294
301
|
// multi-line-comment := '/*' commented-block
|
|
295
|
-
multi_line_comment:
|
|
302
|
+
multi_line_comment: $ =>
|
|
296
303
|
seq('/*', repeat(prec.right(2, choice($.commented_block, /[^*\/]/))), '*/'),
|
|
297
304
|
// commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+) commented-block
|
|
298
|
-
commented_block:
|
|
305
|
+
commented_block: $ =>
|
|
299
306
|
prec.right(1, seq(
|
|
300
307
|
/[^*\/]/,
|
|
301
308
|
repeat(choice($.multi_line_comment, /[^*\/]/)),
|
package/package.json
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tree-sitter-kdl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "KDL grammar for tree-sitter",
|
|
5
5
|
"main": "bindings/node",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"parser",
|
|
8
|
-
"lexer"
|
|
8
|
+
"lexer",
|
|
9
|
+
"kdl"
|
|
9
10
|
],
|
|
10
|
-
"author": "Amaan Qureshi",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/amaanq/tree-sitter-kdl.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "ISC",
|
|
11
|
+
"author": "Amaan Qureshi <amaanq12@gmail.com>",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"Andrew Hlynskyi <ahlincq@gmail.com>"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
19
16
|
"bugs": {
|
|
20
17
|
"url": "https://github.com/amaanq/tree-sitter-kdl/issues"
|
|
21
18
|
},
|
|
@@ -24,9 +21,26 @@
|
|
|
24
21
|
"nan": "^2.17.0"
|
|
25
22
|
},
|
|
26
23
|
"devDependencies": {
|
|
27
|
-
"@types/node": "^18.11.18",
|
|
28
24
|
"eslint": "^8.32.0",
|
|
29
25
|
"eslint-config-google": "^0.14.0",
|
|
30
26
|
"tree-sitter-cli": "^0.20.7"
|
|
31
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"repository": "https://github.com/amaanq/tree-sitter-kdl",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tree-sitter generate && node-gyp build",
|
|
31
|
+
"test": "tree-sitter test && script/parse-examples",
|
|
32
|
+
"parse": "tree-sitter parse",
|
|
33
|
+
"test-windows": "tree-sitter test"
|
|
34
|
+
},
|
|
35
|
+
"tree-sitter": [
|
|
36
|
+
{
|
|
37
|
+
"scope": "source.kdl",
|
|
38
|
+
"file-types": [
|
|
39
|
+
"kdl"
|
|
40
|
+
],
|
|
41
|
+
"highlights": [
|
|
42
|
+
"queries/highlights.scm"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
]
|
|
32
46
|
}
|
package/queries/folds.scm
CHANGED
package/queries/highlights.scm
CHANGED