tree-sitter-kdl 1.0.3 → 2.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/LICENSE +1 -1
- package/README.md +3 -2
- package/binding.gyp +22 -6
- package/bindings/node/binding.cc +12 -23
- package/bindings/node/index.d.ts +60 -0
- package/bindings/node/index.js +33 -15
- package/grammar.js +193 -170
- package/package.json +48 -31
- package/prebuilds/darwin-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-kdl.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-kdl.node +0 -0
- package/prebuilds/win32-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-kdl.node +0 -0
- package/queries/highlights.scm +37 -17
- package/queries/indents.scm +1 -1
- package/queries/injections.scm +10 -0
- package/queries/locals.scm +3 -3
- package/src/grammar.json +744 -761
- package/src/node-types.json +271 -238
- package/src/parser.c +12895 -11901
- package/src/scanner.c +161 -53
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +336 -0
- package/src/tree_sitter/parser.h +79 -17
- package/tree-sitter-kdl.wasm +0 -0
- package/tree-sitter.json +44 -0
- package/.eslintrc.js +0 -20
- package/.gitattributes +0 -7
- package/.github/workflows/ci.yml +0 -34
- package/.github/workflows/fuzz.yml +0 -21
- package/.github/workflows/lint.yml +0 -19
- package/.github/workflows/publish.yml +0 -51
- package/Cargo.toml +0 -27
- package/Package.swift +0 -38
- package/bindings/rust/README.md +0 -36
- package/bindings/rust/build.rs +0 -19
- package/bindings/rust/lib.rs +0 -68
- package/bindings/swift/kdl.h +0 -16
package/src/tree_sitter/parser.h
CHANGED
|
@@ -13,12 +13,16 @@ extern "C" {
|
|
|
13
13
|
#define ts_builtin_sym_end 0
|
|
14
14
|
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
|
15
15
|
|
|
16
|
-
typedef uint16_t TSStateId;
|
|
17
|
-
|
|
18
16
|
#ifndef TREE_SITTER_API_H_
|
|
17
|
+
typedef uint16_t TSStateId;
|
|
19
18
|
typedef uint16_t TSSymbol;
|
|
20
19
|
typedef uint16_t TSFieldId;
|
|
21
20
|
typedef struct TSLanguage TSLanguage;
|
|
21
|
+
typedef struct TSLanguageMetadata {
|
|
22
|
+
uint8_t major_version;
|
|
23
|
+
uint8_t minor_version;
|
|
24
|
+
uint8_t patch_version;
|
|
25
|
+
} TSLanguageMetadata;
|
|
22
26
|
#endif
|
|
23
27
|
|
|
24
28
|
typedef struct {
|
|
@@ -27,10 +31,11 @@ typedef struct {
|
|
|
27
31
|
bool inherited;
|
|
28
32
|
} TSFieldMapEntry;
|
|
29
33
|
|
|
34
|
+
// Used to index the field and supertype maps.
|
|
30
35
|
typedef struct {
|
|
31
36
|
uint16_t index;
|
|
32
37
|
uint16_t length;
|
|
33
|
-
}
|
|
38
|
+
} TSMapSlice;
|
|
34
39
|
|
|
35
40
|
typedef struct {
|
|
36
41
|
bool visible;
|
|
@@ -48,6 +53,7 @@ struct TSLexer {
|
|
|
48
53
|
uint32_t (*get_column)(TSLexer *);
|
|
49
54
|
bool (*is_at_included_range_start)(const TSLexer *);
|
|
50
55
|
bool (*eof)(const TSLexer *);
|
|
56
|
+
void (*log)(const TSLexer *, const char *, ...);
|
|
51
57
|
};
|
|
52
58
|
|
|
53
59
|
typedef enum {
|
|
@@ -79,6 +85,12 @@ typedef struct {
|
|
|
79
85
|
uint16_t external_lex_state;
|
|
80
86
|
} TSLexMode;
|
|
81
87
|
|
|
88
|
+
typedef struct {
|
|
89
|
+
uint16_t lex_state;
|
|
90
|
+
uint16_t external_lex_state;
|
|
91
|
+
uint16_t reserved_word_set_id;
|
|
92
|
+
} TSLexerMode;
|
|
93
|
+
|
|
82
94
|
typedef union {
|
|
83
95
|
TSParseAction action;
|
|
84
96
|
struct {
|
|
@@ -87,8 +99,13 @@ typedef union {
|
|
|
87
99
|
} entry;
|
|
88
100
|
} TSParseActionEntry;
|
|
89
101
|
|
|
102
|
+
typedef struct {
|
|
103
|
+
int32_t start;
|
|
104
|
+
int32_t end;
|
|
105
|
+
} TSCharacterRange;
|
|
106
|
+
|
|
90
107
|
struct TSLanguage {
|
|
91
|
-
uint32_t
|
|
108
|
+
uint32_t abi_version;
|
|
92
109
|
uint32_t symbol_count;
|
|
93
110
|
uint32_t alias_count;
|
|
94
111
|
uint32_t token_count;
|
|
@@ -104,13 +121,13 @@ struct TSLanguage {
|
|
|
104
121
|
const TSParseActionEntry *parse_actions;
|
|
105
122
|
const char * const *symbol_names;
|
|
106
123
|
const char * const *field_names;
|
|
107
|
-
const
|
|
124
|
+
const TSMapSlice *field_map_slices;
|
|
108
125
|
const TSFieldMapEntry *field_map_entries;
|
|
109
126
|
const TSSymbolMetadata *symbol_metadata;
|
|
110
127
|
const TSSymbol *public_symbol_map;
|
|
111
128
|
const uint16_t *alias_map;
|
|
112
129
|
const TSSymbol *alias_sequences;
|
|
113
|
-
const
|
|
130
|
+
const TSLexerMode *lex_modes;
|
|
114
131
|
bool (*lex_fn)(TSLexer *, TSStateId);
|
|
115
132
|
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
|
116
133
|
TSSymbol keyword_capture_token;
|
|
@@ -124,15 +141,48 @@ struct TSLanguage {
|
|
|
124
141
|
void (*deserialize)(void *, const char *, unsigned);
|
|
125
142
|
} external_scanner;
|
|
126
143
|
const TSStateId *primary_state_ids;
|
|
144
|
+
const char *name;
|
|
145
|
+
const TSSymbol *reserved_words;
|
|
146
|
+
uint16_t max_reserved_word_set_size;
|
|
147
|
+
uint32_t supertype_count;
|
|
148
|
+
const TSSymbol *supertype_symbols;
|
|
149
|
+
const TSMapSlice *supertype_map_slices;
|
|
150
|
+
const TSSymbol *supertype_map_entries;
|
|
151
|
+
TSLanguageMetadata metadata;
|
|
127
152
|
};
|
|
128
153
|
|
|
154
|
+
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
|
155
|
+
uint32_t index = 0;
|
|
156
|
+
uint32_t size = len - index;
|
|
157
|
+
while (size > 1) {
|
|
158
|
+
uint32_t half_size = size / 2;
|
|
159
|
+
uint32_t mid_index = index + half_size;
|
|
160
|
+
const TSCharacterRange *range = &ranges[mid_index];
|
|
161
|
+
if (lookahead >= range->start && lookahead <= range->end) {
|
|
162
|
+
return true;
|
|
163
|
+
} else if (lookahead > range->end) {
|
|
164
|
+
index = mid_index;
|
|
165
|
+
}
|
|
166
|
+
size -= half_size;
|
|
167
|
+
}
|
|
168
|
+
const TSCharacterRange *range = &ranges[index];
|
|
169
|
+
return (lookahead >= range->start && lookahead <= range->end);
|
|
170
|
+
}
|
|
171
|
+
|
|
129
172
|
/*
|
|
130
173
|
* Lexer Macros
|
|
131
174
|
*/
|
|
132
175
|
|
|
176
|
+
#ifdef _MSC_VER
|
|
177
|
+
#define UNUSED __pragma(warning(suppress : 4101))
|
|
178
|
+
#else
|
|
179
|
+
#define UNUSED __attribute__((unused))
|
|
180
|
+
#endif
|
|
181
|
+
|
|
133
182
|
#define START_LEXER() \
|
|
134
183
|
bool result = false; \
|
|
135
184
|
bool skip = false; \
|
|
185
|
+
UNUSED \
|
|
136
186
|
bool eof = false; \
|
|
137
187
|
int32_t lookahead; \
|
|
138
188
|
goto start; \
|
|
@@ -148,6 +198,17 @@ struct TSLanguage {
|
|
|
148
198
|
goto next_state; \
|
|
149
199
|
}
|
|
150
200
|
|
|
201
|
+
#define ADVANCE_MAP(...) \
|
|
202
|
+
{ \
|
|
203
|
+
static const uint16_t map[] = { __VA_ARGS__ }; \
|
|
204
|
+
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
|
205
|
+
if (map[i] == lookahead) { \
|
|
206
|
+
state = map[i + 1]; \
|
|
207
|
+
goto next_state; \
|
|
208
|
+
} \
|
|
209
|
+
} \
|
|
210
|
+
}
|
|
211
|
+
|
|
151
212
|
#define SKIP(state_value) \
|
|
152
213
|
{ \
|
|
153
214
|
skip = true; \
|
|
@@ -166,7 +227,7 @@ struct TSLanguage {
|
|
|
166
227
|
* Parse Table Macros
|
|
167
228
|
*/
|
|
168
229
|
|
|
169
|
-
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
|
230
|
+
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
|
|
170
231
|
|
|
171
232
|
#define STATE(id) id
|
|
172
233
|
|
|
@@ -176,7 +237,7 @@ struct TSLanguage {
|
|
|
176
237
|
{{ \
|
|
177
238
|
.shift = { \
|
|
178
239
|
.type = TSParseActionTypeShift, \
|
|
179
|
-
.state = state_value
|
|
240
|
+
.state = (state_value) \
|
|
180
241
|
} \
|
|
181
242
|
}}
|
|
182
243
|
|
|
@@ -184,7 +245,7 @@ struct TSLanguage {
|
|
|
184
245
|
{{ \
|
|
185
246
|
.shift = { \
|
|
186
247
|
.type = TSParseActionTypeShift, \
|
|
187
|
-
.state = state_value,
|
|
248
|
+
.state = (state_value), \
|
|
188
249
|
.repetition = true \
|
|
189
250
|
} \
|
|
190
251
|
}}
|
|
@@ -197,14 +258,15 @@ struct TSLanguage {
|
|
|
197
258
|
} \
|
|
198
259
|
}}
|
|
199
260
|
|
|
200
|
-
#define REDUCE(
|
|
201
|
-
{{
|
|
202
|
-
.reduce = {
|
|
203
|
-
.type = TSParseActionTypeReduce,
|
|
204
|
-
.symbol =
|
|
205
|
-
.child_count =
|
|
206
|
-
|
|
207
|
-
|
|
261
|
+
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
|
262
|
+
{{ \
|
|
263
|
+
.reduce = { \
|
|
264
|
+
.type = TSParseActionTypeReduce, \
|
|
265
|
+
.symbol = symbol_name, \
|
|
266
|
+
.child_count = children, \
|
|
267
|
+
.dynamic_precedence = precedence, \
|
|
268
|
+
.production_id = prod_id \
|
|
269
|
+
}, \
|
|
208
270
|
}}
|
|
209
271
|
|
|
210
272
|
#define RECOVER() \
|
|
Binary file
|
package/tree-sitter.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json",
|
|
3
|
+
"grammars": [
|
|
4
|
+
{
|
|
5
|
+
"name": "kdl",
|
|
6
|
+
"camelcase": "KDL",
|
|
7
|
+
"title": "KDL",
|
|
8
|
+
"scope": "source.kdl",
|
|
9
|
+
"path": ".",
|
|
10
|
+
"file-types": [
|
|
11
|
+
"kdl"
|
|
12
|
+
],
|
|
13
|
+
"highlights": "queries/highlights.scm",
|
|
14
|
+
"injections": "queries/injections.scm",
|
|
15
|
+
"locals": "queries/locals.scm",
|
|
16
|
+
"injection-regex": "^kdl$",
|
|
17
|
+
"class-name": "TreeSitterKDL"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"metadata": {
|
|
21
|
+
"version": "2.0.0",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"description": "KDL grammar for tree-sitter",
|
|
24
|
+
"authors": [
|
|
25
|
+
{
|
|
26
|
+
"name": "Amaan Qureshi",
|
|
27
|
+
"email": "contact@amaanq.com"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"links": {
|
|
31
|
+
"repository": "https://github.com/amaanq/tree-sitter-kdl"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"bindings": {
|
|
35
|
+
"c": true,
|
|
36
|
+
"go": true,
|
|
37
|
+
"java": false,
|
|
38
|
+
"node": true,
|
|
39
|
+
"python": true,
|
|
40
|
+
"rust": true,
|
|
41
|
+
"swift": true,
|
|
42
|
+
"zig": false
|
|
43
|
+
}
|
|
44
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
DELETED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
name: Publish
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
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@v2
|
|
50
|
-
with:
|
|
51
|
-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
package/Cargo.toml
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "tree-sitter-kdl"
|
|
3
|
-
description = "KDL grammar for tree-sitter"
|
|
4
|
-
version = "1.0.3"
|
|
5
|
-
authors = [
|
|
6
|
-
"Amaan Qureshi <amaanq12@gmail.com>",
|
|
7
|
-
"Andrew Hlynskyi <ahlincq@gmail.com>",
|
|
8
|
-
]
|
|
9
|
-
license = "MIT"
|
|
10
|
-
readme = "bindings/rust/README.md"
|
|
11
|
-
keywords = ["incremental", "parsing", "kdl"]
|
|
12
|
-
categories = ["parsing", "text-editors"]
|
|
13
|
-
repository = "https://github.com/amaanq/tree-sitter-kdl"
|
|
14
|
-
edition = "2021"
|
|
15
|
-
autoexamples = false
|
|
16
|
-
|
|
17
|
-
build = "bindings/rust/build.rs"
|
|
18
|
-
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
|
19
|
-
|
|
20
|
-
[lib]
|
|
21
|
-
path = "bindings/rust/lib.rs"
|
|
22
|
-
|
|
23
|
-
[dependencies]
|
|
24
|
-
tree-sitter = "~0.20.3"
|
|
25
|
-
|
|
26
|
-
[build-dependencies]
|
|
27
|
-
cc = "1.0"
|
package/Package.swift
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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/bindings/rust/README.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
let scanner_path = src_dir.join("scanner.c");
|
|
14
|
-
c_config.file(&scanner_path);
|
|
15
|
-
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
16
|
-
|
|
17
|
-
c_config.compile("parser");
|
|
18
|
-
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
|
19
|
-
}
|
package/bindings/rust/lib.rs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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.
|
|
7
|
-
//!
|
|
8
|
-
//! Typically, you will use the [language][language func] function to add this language to a
|
|
9
|
-
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
10
|
-
//!
|
|
11
|
-
//! ```
|
|
12
|
-
//! let code = "";
|
|
13
|
-
//! let mut parser = tree_sitter::Parser::new();
|
|
14
|
-
//! parser.set_language(tree_sitter_kdl::language()).expect("Error loading KDL grammar");
|
|
15
|
-
//! let tree = parser.parse(code, None).unwrap();
|
|
16
|
-
//! ```
|
|
17
|
-
//!
|
|
18
|
-
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
19
|
-
//! [language func]: fn.language.html
|
|
20
|
-
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
21
|
-
//! [tree-sitter]: https://tree-sitter.github.io/
|
|
22
|
-
|
|
23
|
-
use tree_sitter::Language;
|
|
24
|
-
|
|
25
|
-
extern "C" {
|
|
26
|
-
fn tree_sitter_kdl() -> Language;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// Get the tree-sitter [Language][] for this grammar.
|
|
30
|
-
///
|
|
31
|
-
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
32
|
-
pub fn language() -> Language {
|
|
33
|
-
unsafe { tree_sitter_kdl() }
|
|
34
|
-
}
|
|
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
|
-
|
|
54
|
-
/// The content of the [`node-types.json`][] file for this grammar.
|
|
55
|
-
///
|
|
56
|
-
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
57
|
-
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
58
|
-
|
|
59
|
-
#[cfg(test)]
|
|
60
|
-
mod tests {
|
|
61
|
-
#[test]
|
|
62
|
-
fn test_can_load_grammar() {
|
|
63
|
-
let mut parser = tree_sitter::Parser::new();
|
|
64
|
-
parser
|
|
65
|
-
.set_language(super::language())
|
|
66
|
-
.expect("Error loading KDL grammar");
|
|
67
|
-
}
|
|
68
|
-
}
|
package/bindings/swift/kdl.h
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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_
|