tree-sitter-kdl 1.0.1 → 1.0.3
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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/lint.yml +19 -0
- package/.github/workflows/publish.yml +2 -2
- 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 +27 -11
- package/bindings/swift/kdl.h +16 -0
- package/grammar.js +21 -35
- package/package.json +1 -1
- package/queries/highlights.scm +6 -3
- package/src/grammar.json +5 -63
- package/src/node-types.json +4 -38
- package/src/parser.c +4162 -6112
- package/src/scanner.c +50 -4
- 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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- "**"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
- name: Install modules
|
|
17
|
+
run: npm install
|
|
18
|
+
- name: Run ESLint
|
|
19
|
+
run: npm run lint
|
|
@@ -3,7 +3,7 @@ name: Publish
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
|
-
-
|
|
6
|
+
- master
|
|
7
7
|
tags:
|
|
8
8
|
- "v*"
|
|
9
9
|
workflow_dispatch:
|
|
@@ -46,6 +46,6 @@ jobs:
|
|
|
46
46
|
profile: minimal
|
|
47
47
|
toolchain: stable
|
|
48
48
|
override: true
|
|
49
|
-
- uses: katyo/publish-crates@
|
|
49
|
+
- uses: katyo/publish-crates@v2
|
|
50
50
|
with:
|
|
51
51
|
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
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.3"
|
|
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:
|
|
@@ -6,7 +11,7 @@
|
|
|
6
11
|
//! ```
|
|
7
12
|
//! let code = "";
|
|
8
13
|
//! let mut parser = tree_sitter::Parser::new();
|
|
9
|
-
//! parser.set_language(tree_sitter_kdl::language()).expect("Error loading
|
|
14
|
+
//! parser.set_language(tree_sitter_kdl::language()).expect("Error loading KDL grammar");
|
|
10
15
|
//! let tree = parser.parse(code, None).unwrap();
|
|
11
16
|
//! ```
|
|
12
17
|
//!
|
|
@@ -28,17 +33,28 @@ pub fn language() -> Language {
|
|
|
28
33
|
unsafe { tree_sitter_kdl() }
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
/// The source of the Rust tree-sitter grammar description.
|
|
37
|
+
pub const GRAMMAR: &str = include_str!("../../grammar.js");
|
|
38
|
+
|
|
39
|
+
/// The folds query for this language.
|
|
40
|
+
pub const FOLDS_QUERY: &str = include_str!("../../queries/folds.scm");
|
|
41
|
+
|
|
42
|
+
/// The syntax highlighting query for this language.
|
|
43
|
+
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
|
44
|
+
|
|
45
|
+
/// The indents query for this language.
|
|
46
|
+
pub const INDENTS_QUERY: &str = include_str!("../../queries/indents.scm");
|
|
47
|
+
|
|
48
|
+
/// The injection query for this language.
|
|
49
|
+
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
|
|
50
|
+
|
|
51
|
+
/// The symbol tagging query for this language.
|
|
52
|
+
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
|
|
53
|
+
|
|
31
54
|
/// The content of the [`node-types.json`][] file for this grammar.
|
|
32
55
|
///
|
|
33
56
|
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
34
|
-
pub const NODE_TYPES: &
|
|
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");
|
|
57
|
+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
42
58
|
|
|
43
59
|
#[cfg(test)]
|
|
44
60
|
mod tests {
|
|
@@ -47,6 +63,6 @@ mod tests {
|
|
|
47
63
|
let mut parser = tree_sitter::Parser::new();
|
|
48
64
|
parser
|
|
49
65
|
.set_language(super::language())
|
|
50
|
-
.expect("Error loading
|
|
66
|
+
.expect("Error loading KDL grammar");
|
|
51
67
|
}
|
|
52
68
|
}
|
|
@@ -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
|
|
@@ -14,10 +13,6 @@
|
|
|
14
13
|
/// <reference types="tree-sitter-cli/dsl" />
|
|
15
14
|
// @ts-check
|
|
16
15
|
|
|
17
|
-
const PREC = {
|
|
18
|
-
node: 1,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
16
|
const ANNOTATION_BUILTINS = [
|
|
22
17
|
'i8',
|
|
23
18
|
'i16',
|
|
@@ -67,9 +62,9 @@ module.exports = grammar({
|
|
|
67
62
|
[$.node_children],
|
|
68
63
|
],
|
|
69
64
|
|
|
70
|
-
|
|
65
|
+
externals: $ => [$._eof, $.multi_line_comment],
|
|
71
66
|
|
|
72
|
-
|
|
67
|
+
extras: $ => [$.multi_line_comment],
|
|
73
68
|
|
|
74
69
|
word: $ => $._normal_bare_identifier,
|
|
75
70
|
|
|
@@ -89,7 +84,7 @@ module.exports = grammar({
|
|
|
89
84
|
),
|
|
90
85
|
|
|
91
86
|
// node := ('/-' node-space*)? type? identifier (node-space+ node-prop-or-arg)* (node-space* node-children ws*)? node-space* node-terminator
|
|
92
|
-
node: $ => prec(
|
|
87
|
+
node: $ => prec(1,
|
|
93
88
|
seq(
|
|
94
89
|
alias(optional(seq('/-', repeat($._node_space))), $.node_comment),
|
|
95
90
|
optional($.type),
|
|
@@ -142,31 +137,31 @@ module.exports = grammar({
|
|
|
142
137
|
),
|
|
143
138
|
|
|
144
139
|
// _normal_bare_identifier: $ => $.__identifier_char_no_digit_sign,
|
|
145
|
-
_normal_bare_identifier:
|
|
140
|
+
_normal_bare_identifier: _ => token(
|
|
146
141
|
seq(
|
|
147
142
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}_~!@#\$%\^&\*.:'\|\?&&[^\s\d\/(){}<>;\[\]=,"]]/,
|
|
148
143
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\/(){}<>;\[\]=,"]]*/,
|
|
149
144
|
),
|
|
150
145
|
),
|
|
151
146
|
// identifier-char := unicode - linespace - [\/(){}<>;[]=,"]
|
|
152
|
-
_identifier_char:
|
|
147
|
+
_identifier_char: _ => token(
|
|
153
148
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\/(){}<>;\[\]=,"]]/,
|
|
154
149
|
),
|
|
155
150
|
|
|
156
151
|
// can't start with a digit
|
|
157
|
-
__identifier_char_no_digit:
|
|
152
|
+
__identifier_char_no_digit: _ => token(
|
|
158
153
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\d\/(){}<>;\[\]=,"]]/,
|
|
159
154
|
),
|
|
160
155
|
|
|
161
156
|
// can't start with a digit or sign
|
|
162
|
-
__identifier_char_no_digit_sign:
|
|
157
|
+
__identifier_char_no_digit_sign: _ => token(
|
|
163
158
|
/[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?&&[^\s\d\+\-\/(){}<>;\[\]=,"]]/,
|
|
164
159
|
),
|
|
165
160
|
|
|
166
161
|
// keyword := boolean | 'null'
|
|
167
162
|
keyword: $ => choice($.boolean, 'null'),
|
|
168
163
|
// type annotations
|
|
169
|
-
annotation_type:
|
|
164
|
+
annotation_type: _ => choice(...ANNOTATION_BUILTINS),
|
|
170
165
|
// prop := identifier '=' value
|
|
171
166
|
prop: $ => seq($.identifier, '=', $.value),
|
|
172
167
|
// value := type? (string | number | keyword)
|
|
@@ -182,18 +177,18 @@ module.exports = grammar({
|
|
|
182
177
|
// character := '\' escape | [^\"]
|
|
183
178
|
_character: $ => choice($.escape, /[^"]/),
|
|
184
179
|
// escape := ["\\/bfnrt] | 'u{' hex-digit{1, 6} '}'
|
|
185
|
-
escape:
|
|
180
|
+
escape: _ =>
|
|
186
181
|
token.immediate(/\\\\|\\"|\\\/|\\b|\\f|\\n|\\r|\\t|\\u\{[0-9a-fA-F]{1,6}\}/),
|
|
187
182
|
// hex-digit := [0-9a-fA-F]
|
|
188
|
-
_hex_digit:
|
|
183
|
+
_hex_digit: _ => /[0-9a-fA-F]/,
|
|
189
184
|
|
|
190
185
|
// // raw-string := 'r' raw-string-hash
|
|
191
186
|
// raw_string: $ => seq('r', $._raw_string_hash),
|
|
192
187
|
// // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
|
|
193
188
|
// _raw_string_hash: $ => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
|
|
194
189
|
// // raw-string-quotes := '"' .* '"'
|
|
195
|
-
// _raw_string_quotes:
|
|
196
|
-
_raw_string:
|
|
190
|
+
// _raw_string_quotes: _ => seq('"', /.*/, '"'),
|
|
191
|
+
_raw_string: _ =>
|
|
197
192
|
seq(
|
|
198
193
|
choice(
|
|
199
194
|
// raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
|
|
@@ -221,9 +216,9 @@ module.exports = grammar({
|
|
|
221
216
|
// integer := digit (digit | '_')*
|
|
222
217
|
_integer: $ => seq($._digit, repeat(choice($._digit, '_'))),
|
|
223
218
|
// digit := [0-9]
|
|
224
|
-
_digit:
|
|
219
|
+
_digit: _ => /[0-9]/,
|
|
225
220
|
// sign := '+' | '-'
|
|
226
|
-
_sign:
|
|
221
|
+
_sign: _ => choice('+', '-'),
|
|
227
222
|
|
|
228
223
|
// hex := sign? '0x' hex-digit (hex-digit | '_')*
|
|
229
224
|
_hex: $ => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
|
|
@@ -233,7 +228,7 @@ module.exports = grammar({
|
|
|
233
228
|
_binary: $ => seq(optional($._sign), '0b', choice('0', '1'), repeat(choice('0', '1', '_'))),
|
|
234
229
|
|
|
235
230
|
// boolean := 'true' | 'false'
|
|
236
|
-
boolean:
|
|
231
|
+
boolean: _ => choice('true', 'false'),
|
|
237
232
|
|
|
238
233
|
// escline := '\\' ws* (single-line-comment | newline)
|
|
239
234
|
_escline: $ => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
|
|
@@ -256,13 +251,13 @@ module.exports = grammar({
|
|
|
256
251
|
// │ PS Paragraph Separator U+2029 │
|
|
257
252
|
// ╰──────────────────────────────────────────────────────────╯
|
|
258
253
|
// Note that for the purpose of new lines, CRLF is considered a single newline.
|
|
259
|
-
_newline:
|
|
254
|
+
_newline: _ => choice(/\r'/, /\n/, /\r\n/, /\u0085/, /\u000C/, /\u2028/, /\u2029/),
|
|
260
255
|
|
|
261
256
|
// ws := bom | unicode-space | multi-line-comment
|
|
262
257
|
_ws: $ => choice($._bom, $._unicode_space, $.multi_line_comment),
|
|
263
258
|
|
|
264
259
|
// bom := '\u{FEFF}'
|
|
265
|
-
_bom:
|
|
260
|
+
_bom: _ => /\u{FEFF}/,
|
|
266
261
|
|
|
267
262
|
// unicode-space := See Table (All White_Space unicode characters which are not `newline`)
|
|
268
263
|
// Whitespace
|
|
@@ -289,24 +284,15 @@ module.exports = grammar({
|
|
|
289
284
|
// │ Medium Mathematical Space U+205F │
|
|
290
285
|
// │ Ideographic Space U+3000 │
|
|
291
286
|
// ╰────────────────────────────────────╯
|
|
292
|
-
_unicode_space:
|
|
287
|
+
_unicode_space: _ =>
|
|
293
288
|
/[\u0009\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/,
|
|
294
289
|
|
|
295
290
|
// single-line-comment := '//' ^newline+ (newline | eof)
|
|
296
291
|
single_line_comment: $ =>
|
|
297
292
|
seq(
|
|
298
293
|
'//',
|
|
299
|
-
|
|
294
|
+
repeat(/[^\r\n\u0085\u000C\u2028\u2029]/),
|
|
300
295
|
choice($._newline, $._eof),
|
|
301
296
|
),
|
|
302
|
-
// multi-line-comment := '/*' commented-block
|
|
303
|
-
multi_line_comment: $ =>
|
|
304
|
-
seq('/*', repeat(prec.right(2, choice($.commented_block, /[^*\/]/))), '*/'),
|
|
305
|
-
// commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+) commented-block
|
|
306
|
-
commented_block: $ =>
|
|
307
|
-
prec.right(1, seq(
|
|
308
|
-
/[^*\/]/,
|
|
309
|
-
repeat(choice($.multi_line_comment, /[^*\/]/)),
|
|
310
|
-
)),
|
|
311
297
|
},
|
|
312
298
|
});
|
package/package.json
CHANGED
package/queries/highlights.scm
CHANGED
|
@@ -31,18 +31,21 @@
|
|
|
31
31
|
|
|
32
32
|
(number (decimal) @float)
|
|
33
33
|
(number (exponent) @float)
|
|
34
|
-
(number (decimal) (exponent) @float)
|
|
35
34
|
|
|
36
35
|
(boolean) @boolean
|
|
37
36
|
|
|
38
|
-
; Misc
|
|
39
|
-
|
|
40
37
|
"null" @constant.builtin
|
|
41
38
|
|
|
39
|
+
; Punctuation
|
|
40
|
+
|
|
42
41
|
["{" "}"] @punctuation.bracket
|
|
43
42
|
|
|
44
43
|
["(" ")"] @punctuation.bracket
|
|
45
44
|
|
|
45
|
+
[
|
|
46
|
+
";"
|
|
47
|
+
] @punctuation.delimiter
|
|
48
|
+
|
|
46
49
|
; Comments
|
|
47
50
|
|
|
48
51
|
[
|
package/src/grammar.json
CHANGED
|
@@ -1282,7 +1282,7 @@
|
|
|
1282
1282
|
"value": "//"
|
|
1283
1283
|
},
|
|
1284
1284
|
{
|
|
1285
|
-
"type": "
|
|
1285
|
+
"type": "REPEAT",
|
|
1286
1286
|
"content": {
|
|
1287
1287
|
"type": "PATTERN",
|
|
1288
1288
|
"value": "[^\\r\\n\\u0085\\u000C\\u2028\\u2029]"
|
|
@@ -1302,68 +1302,6 @@
|
|
|
1302
1302
|
]
|
|
1303
1303
|
}
|
|
1304
1304
|
]
|
|
1305
|
-
},
|
|
1306
|
-
"multi_line_comment": {
|
|
1307
|
-
"type": "SEQ",
|
|
1308
|
-
"members": [
|
|
1309
|
-
{
|
|
1310
|
-
"type": "STRING",
|
|
1311
|
-
"value": "/*"
|
|
1312
|
-
},
|
|
1313
|
-
{
|
|
1314
|
-
"type": "REPEAT",
|
|
1315
|
-
"content": {
|
|
1316
|
-
"type": "PREC_RIGHT",
|
|
1317
|
-
"value": 2,
|
|
1318
|
-
"content": {
|
|
1319
|
-
"type": "CHOICE",
|
|
1320
|
-
"members": [
|
|
1321
|
-
{
|
|
1322
|
-
"type": "SYMBOL",
|
|
1323
|
-
"name": "commented_block"
|
|
1324
|
-
},
|
|
1325
|
-
{
|
|
1326
|
-
"type": "PATTERN",
|
|
1327
|
-
"value": "[^*\\/]"
|
|
1328
|
-
}
|
|
1329
|
-
]
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
},
|
|
1333
|
-
{
|
|
1334
|
-
"type": "STRING",
|
|
1335
|
-
"value": "*/"
|
|
1336
|
-
}
|
|
1337
|
-
]
|
|
1338
|
-
},
|
|
1339
|
-
"commented_block": {
|
|
1340
|
-
"type": "PREC_RIGHT",
|
|
1341
|
-
"value": 1,
|
|
1342
|
-
"content": {
|
|
1343
|
-
"type": "SEQ",
|
|
1344
|
-
"members": [
|
|
1345
|
-
{
|
|
1346
|
-
"type": "PATTERN",
|
|
1347
|
-
"value": "[^*\\/]"
|
|
1348
|
-
},
|
|
1349
|
-
{
|
|
1350
|
-
"type": "REPEAT",
|
|
1351
|
-
"content": {
|
|
1352
|
-
"type": "CHOICE",
|
|
1353
|
-
"members": [
|
|
1354
|
-
{
|
|
1355
|
-
"type": "SYMBOL",
|
|
1356
|
-
"name": "multi_line_comment"
|
|
1357
|
-
},
|
|
1358
|
-
{
|
|
1359
|
-
"type": "PATTERN",
|
|
1360
|
-
"value": "[^*\\/]"
|
|
1361
|
-
}
|
|
1362
|
-
]
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
]
|
|
1366
|
-
}
|
|
1367
1305
|
}
|
|
1368
1306
|
},
|
|
1369
1307
|
"extras": [
|
|
@@ -1388,6 +1326,10 @@
|
|
|
1388
1326
|
{
|
|
1389
1327
|
"type": "SYMBOL",
|
|
1390
1328
|
"name": "_eof"
|
|
1329
|
+
},
|
|
1330
|
+
{
|
|
1331
|
+
"type": "SYMBOL",
|
|
1332
|
+
"name": "multi_line_comment"
|
|
1391
1333
|
}
|
|
1392
1334
|
],
|
|
1393
1335
|
"inline": [],
|