tree-sitter-kdl 1.0.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/.eslintrc.js +20 -0
- package/.gitattributes +3 -0
- package/.github/workflows/build.yml +51 -0
- package/.github/workflows/ci.yml +34 -0
- package/.github/workflows/fuzz.yml +21 -0
- package/Cargo.toml +22 -0
- package/README.md +5 -0
- package/binding.gyp +20 -0
- package/bindings/node/binding.cc +28 -0
- package/bindings/node/index.js +19 -0
- package/bindings/rust/build.rs +38 -0
- package/bindings/rust/lib.rs +52 -0
- package/examples/01-basic.kdl +1 -0
- package/examples/02-multiple-values.kdl +1 -0
- package/examples/03-properties.kdl +1 -0
- package/examples/04-child-nodes.kdl +6 -0
- package/examples/05-node-terminators.kdl +1 -0
- package/examples/06-string-formats.kdl +2 -0
- package/examples/07-multiline-string.kdl +3 -0
- package/examples/08-raw-string.kdl +1 -0
- package/examples/09-number.kdl +1 -0
- package/examples/10-number-forms.kdl +3 -0
- package/examples/11-number-with-underscores.kdl +1 -0
- package/examples/12-comments.kdl +11 -0
- package/examples/13-slashdash-comments.kdl +11 -0
- package/examples/14-type-annotations.kdl +4 -0
- package/examples/15-rich-example.kdl +21 -0
- package/grammar.js +304 -0
- package/package.json +32 -0
- package/queries/folds.scm +3 -0
- package/queries/highlights.scm +55 -0
- package/script/known_failures.txt +0 -0
- package/script/parse-examples +40 -0
- package/src/grammar.json +1396 -0
- package/src/node-types.json +626 -0
- package/src/parser.c +17477 -0
- package/src/scanner.c +30 -0
- package/src/tree_sitter/parser.h +224 -0
- package/test/corpus/node.txt +2784 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
'env': {
|
|
3
|
+
'commonjs': true,
|
|
4
|
+
'es2021': true,
|
|
5
|
+
},
|
|
6
|
+
'extends': 'google',
|
|
7
|
+
'overrides': [
|
|
8
|
+
],
|
|
9
|
+
'parserOptions': {
|
|
10
|
+
'ecmaVersion': 'latest',
|
|
11
|
+
'sourceType': 'module',
|
|
12
|
+
},
|
|
13
|
+
'rules': {
|
|
14
|
+
'indent': ['error', 2, {'SwitchCase': 1}],
|
|
15
|
+
'max-len': [
|
|
16
|
+
'error',
|
|
17
|
+
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
};
|
package/.gitattributes
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: Build and Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
tags:
|
|
8
|
+
- "v*"
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
- uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 16
|
|
19
|
+
- run: npm install
|
|
20
|
+
- run: npm test
|
|
21
|
+
|
|
22
|
+
publish-npm:
|
|
23
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
24
|
+
needs: build
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
- uses: actions/setup-node@v3
|
|
30
|
+
with:
|
|
31
|
+
node-version: 16
|
|
32
|
+
registry-url: https://registry.npmjs.org/
|
|
33
|
+
- run: npm install
|
|
34
|
+
- run: npm publish
|
|
35
|
+
env:
|
|
36
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
37
|
+
|
|
38
|
+
publish-crates:
|
|
39
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
40
|
+
needs: build
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v3
|
|
44
|
+
- uses: actions-rs/toolchain@v1
|
|
45
|
+
with:
|
|
46
|
+
profile: minimal
|
|
47
|
+
toolchain: stable
|
|
48
|
+
override: true
|
|
49
|
+
- uses: katyo/publish-crates@v1
|
|
50
|
+
with:
|
|
51
|
+
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Build/test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "master"
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- "**"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: true
|
|
16
|
+
matrix:
|
|
17
|
+
os: [macos-latest, ubuntu-latest]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
- uses: actions/setup-node@v2
|
|
21
|
+
with:
|
|
22
|
+
node-version: 16
|
|
23
|
+
- run: npm install
|
|
24
|
+
- run: npm test
|
|
25
|
+
|
|
26
|
+
test_windows:
|
|
27
|
+
runs-on: windows-2019
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v3
|
|
30
|
+
- uses: actions/setup-node@v2
|
|
31
|
+
with:
|
|
32
|
+
node-version: 16
|
|
33
|
+
- run: npm install
|
|
34
|
+
- run: npm run-script test-windows
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Fuzz parser
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
paths:
|
|
6
|
+
- src/scanner.c
|
|
7
|
+
pull_request:
|
|
8
|
+
paths:
|
|
9
|
+
- src/scanner.c
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: Parser fuzzing
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v3
|
|
17
|
+
- uses: vigoux/tree-sitter-fuzz-action@v1
|
|
18
|
+
with:
|
|
19
|
+
language: kdl
|
|
20
|
+
external-scanner: src/scanner.c
|
|
21
|
+
time: 60
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tree-sitter-kdl"
|
|
3
|
+
description = "kdl grammar for the tree-sitter parsing library"
|
|
4
|
+
version = "0.0.1"
|
|
5
|
+
authors = ["amaanq (Amaan Qureshi) <amaanq12@gmail.com>"]
|
|
6
|
+
keywords = ["incremental", "parsing", "kdl"]
|
|
7
|
+
categories = ["parsing", "text-editors"]
|
|
8
|
+
repository = "https://github.com/tree-sitter/tree-sitter-kdl"
|
|
9
|
+
edition = "2018"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
|
|
12
|
+
build = "bindings/rust/build.rs"
|
|
13
|
+
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
|
14
|
+
|
|
15
|
+
[lib]
|
|
16
|
+
path = "bindings/rust/lib.rs"
|
|
17
|
+
|
|
18
|
+
[dependencies]
|
|
19
|
+
tree-sitter = "~0.20.3"
|
|
20
|
+
|
|
21
|
+
[build-dependencies]
|
|
22
|
+
cc = "1.0"
|
package/README.md
ADDED
package/binding.gyp
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_kdl_binding",
|
|
5
|
+
"include_dirs": [
|
|
6
|
+
"<!(node -e \"require('nan')\")",
|
|
7
|
+
"src"
|
|
8
|
+
],
|
|
9
|
+
"sources": [
|
|
10
|
+
"bindings/node/binding.cc",
|
|
11
|
+
"src/parser.c",
|
|
12
|
+
"src/scanner.c",
|
|
13
|
+
# If your language uses an external scanner, add it here.
|
|
14
|
+
],
|
|
15
|
+
"cflags_c": [
|
|
16
|
+
"-std=c99",
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#include "tree_sitter/parser.h"
|
|
2
|
+
#include <node.h>
|
|
3
|
+
#include "nan.h"
|
|
4
|
+
|
|
5
|
+
using namespace v8;
|
|
6
|
+
|
|
7
|
+
extern "C" TSLanguage * tree_sitter_kdl();
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
NAN_METHOD(New) {}
|
|
12
|
+
|
|
13
|
+
void Init(Local<Object> exports, Local<Object> module) {
|
|
14
|
+
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
|
15
|
+
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
|
16
|
+
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
17
|
+
|
|
18
|
+
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
|
19
|
+
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
|
20
|
+
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_kdl());
|
|
21
|
+
|
|
22
|
+
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("kdl").ToLocalChecked());
|
|
23
|
+
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
NODE_MODULE(tree_sitter_kdl_binding, Init)
|
|
27
|
+
|
|
28
|
+
} // namespace
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
try {
|
|
2
|
+
module.exports = require("../../build/Release/tree_sitter_kdl_binding");
|
|
3
|
+
} catch (error1) {
|
|
4
|
+
if (error1.code !== 'MODULE_NOT_FOUND') {
|
|
5
|
+
throw error1;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
module.exports = require("../../build/Debug/tree_sitter_kdl_binding");
|
|
9
|
+
} catch (error2) {
|
|
10
|
+
if (error2.code !== 'MODULE_NOT_FOUND') {
|
|
11
|
+
throw error2;
|
|
12
|
+
}
|
|
13
|
+
throw error1
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
19
|
+
} catch (_) {}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
fn main() {
|
|
2
|
+
let src_dir = std::path::Path::new("src");
|
|
3
|
+
|
|
4
|
+
let mut c_config = cc::Build::new();
|
|
5
|
+
c_config.include(src_dir);
|
|
6
|
+
c_config
|
|
7
|
+
.flag_if_supported("-Wno-unused-parameter")
|
|
8
|
+
.flag_if_supported("-Wno-unused-but-set-variable")
|
|
9
|
+
.flag_if_supported("-Wno-trigraphs");
|
|
10
|
+
let parser_path = src_dir.join("parser.c");
|
|
11
|
+
c_config.file(&parser_path);
|
|
12
|
+
|
|
13
|
+
// If your language uses an external scanner written in C,
|
|
14
|
+
// then include this block of code:
|
|
15
|
+
|
|
16
|
+
let scanner_path = src_dir.join("scanner.c");
|
|
17
|
+
c_config.file(&scanner_path);
|
|
18
|
+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
19
|
+
|
|
20
|
+
c_config.compile("parser");
|
|
21
|
+
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//! This crate provides kdl language support for the [tree-sitter][] parsing library.
|
|
2
|
+
//!
|
|
3
|
+
//! Typically, you will use the [language][language func] function to add this language to a
|
|
4
|
+
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
5
|
+
//!
|
|
6
|
+
//! ```
|
|
7
|
+
//! let code = "";
|
|
8
|
+
//! let mut parser = tree_sitter::Parser::new();
|
|
9
|
+
//! parser.set_language(tree_sitter_kdl::language()).expect("Error loading kdl grammar");
|
|
10
|
+
//! let tree = parser.parse(code, None).unwrap();
|
|
11
|
+
//! ```
|
|
12
|
+
//!
|
|
13
|
+
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
14
|
+
//! [language func]: fn.language.html
|
|
15
|
+
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
16
|
+
//! [tree-sitter]: https://tree-sitter.github.io/
|
|
17
|
+
|
|
18
|
+
use tree_sitter::Language;
|
|
19
|
+
|
|
20
|
+
extern "C" {
|
|
21
|
+
fn tree_sitter_kdl() -> Language;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Get the tree-sitter [Language][] for this grammar.
|
|
25
|
+
///
|
|
26
|
+
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
27
|
+
pub fn language() -> Language {
|
|
28
|
+
unsafe { tree_sitter_kdl() }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// The content of the [`node-types.json`][] file for this grammar.
|
|
32
|
+
///
|
|
33
|
+
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
34
|
+
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
|
35
|
+
|
|
36
|
+
// Uncomment these to include any queries that this grammar contains
|
|
37
|
+
|
|
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
|
+
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
|
42
|
+
|
|
43
|
+
#[cfg(test)]
|
|
44
|
+
mod tests {
|
|
45
|
+
#[test]
|
|
46
|
+
fn test_can_load_grammar() {
|
|
47
|
+
let mut parser = tree_sitter::Parser::new();
|
|
48
|
+
parser
|
|
49
|
+
.set_language(super::language())
|
|
50
|
+
.expect("Error loading kdl language");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
title "Hello, World"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bookmarks 12 15 188 1234
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
author "Alex Monad" email="alex@example.com" active=true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node1; node2; node3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
other-raw r#"hello"world"#
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
num 1.234e-42
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bignum 1_000_000
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|