@willbooster/tree-sitter-c 20.0.0 → 22.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/README.md +13 -11
- package/grammar.js +14 -3
- package/package.json +6 -7
- package/src/node-types.json +4 -0
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -3
- package/queries/highlights.scm +0 -122
- package/queries/tags.scm +0 -9
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-c/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-c/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-c)
|
|
10
10
|
|
|
11
11
|
C grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -15,6 +15,13 @@ to its authors and contributors. This is not an official release of that project
|
|
|
15
15
|
This fork fixes parsing bugs and raises conformance with the ISO C standard
|
|
16
16
|
([C23 working draft N3220](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)).
|
|
17
17
|
|
|
18
|
+
## Support Scope
|
|
19
|
+
|
|
20
|
+
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
21
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
|
|
22
|
+
but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
23
|
+
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
24
|
+
|
|
18
25
|
## Usage
|
|
19
26
|
|
|
20
27
|
The npm package ships `tree-sitter-c.wasm` for
|
|
@@ -57,7 +64,7 @@ const parser = new Parser();
|
|
|
57
64
|
parser.setLanguage(await Language.load(c));
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
The package also ships `grammar.js`, scanner sources under `src/`,
|
|
67
|
+
The package also ships `grammar.js`, scanner sources under `src/`,
|
|
61
68
|
and the node types in `src/node-types.json` for grammars extending C (such as C++).
|
|
62
69
|
The scanner sources include `scanner.c`, `pragma.h`, `identifier.h`, `keywords.h`, `functionMacro.h`,
|
|
63
70
|
`conditionalMacro.h`, and `gnuRawString.h`.
|
|
@@ -185,10 +192,9 @@ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-
|
|
|
185
192
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
186
193
|
fuzzed with, at version 15.0.3 or later within 15.x. No other runtime loads the parser:
|
|
187
194
|
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "20" }
|
|
195
|
+
```sh
|
|
196
|
+
cargo add willbooster-tree-sitter@15.0.3 --rename tree-sitter
|
|
197
|
+
cargo add willbooster-tree-sitter-c --rename tree-sitter-c
|
|
192
198
|
```
|
|
193
199
|
|
|
194
200
|
```rust
|
|
@@ -224,9 +230,6 @@ and the release build regenerate the parsers before compiling them.
|
|
|
224
230
|
`bun run test` runs:
|
|
225
231
|
|
|
226
232
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
227
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
228
|
-
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
229
|
-
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
|
|
230
233
|
- a check that the real-world C files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
|
|
231
234
|
parse exactly as listed in `script/known-failures.txt`. Many of the listed files use preprocessor conditionals or
|
|
232
235
|
macros that tree-sitter parses without expanding them. The first run clones the repositories. The example
|
|
@@ -242,8 +245,7 @@ and the release build regenerate the parsers before compiling them.
|
|
|
242
245
|
Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
|
|
243
246
|
|
|
244
247
|
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
245
|
-
by every checkout
|
|
246
|
-
afterwards.
|
|
248
|
+
by every checkout.
|
|
247
249
|
|
|
248
250
|
CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
|
|
249
251
|
parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
package/grammar.js
CHANGED
|
@@ -636,18 +636,20 @@ module.exports = Object.assign(
|
|
|
636
636
|
...preprocIf('_in_statement', () => sym('_block_item')),
|
|
637
637
|
...preprocIf('_in_single_case', () => sym('_single_case_body'), 0, true),
|
|
638
638
|
...preprocIf('_in_field_declaration_list', () => sym('_field_declaration_list_item')),
|
|
639
|
-
...preprocIf('_in_enumerator_list', () =>
|
|
639
|
+
...preprocIf('_in_enumerator_list', () => sym('_enumerator_list_item')),
|
|
640
640
|
...preprocIf(
|
|
641
641
|
'_in_enumerator_list_no_comma',
|
|
642
642
|
() =>
|
|
643
643
|
choice(
|
|
644
|
-
seq(
|
|
645
|
-
sym('
|
|
644
|
+
seq(repeat(sym('_enumerator_list_item')), sym('enumerator'), optional(sym('_enumerator_directives'))),
|
|
645
|
+
repeat1(sym('_enumerator_list_item'))
|
|
646
646
|
),
|
|
647
647
|
0,
|
|
648
648
|
false
|
|
649
649
|
),
|
|
650
650
|
|
|
651
|
+
_enumerator_list_item: ($) => choice(seq($.enumerator, ','), $._enumerator_macro, $._enumerator_directives),
|
|
652
|
+
|
|
651
653
|
_enumerator_directives: ($) => prec.right(repeat1($.preproc_call)),
|
|
652
654
|
|
|
653
655
|
_preproc_newline: () => token.immediate(/\r?\n/),
|
|
@@ -1413,6 +1415,7 @@ module.exports = Object.assign(
|
|
|
1413
1415
|
repeat(
|
|
1414
1416
|
choice(
|
|
1415
1417
|
seq($.enumerator, ','),
|
|
1418
|
+
$._enumerator_macro,
|
|
1416
1419
|
alias(sym('preproc_if_in_enumerator_list'), sym('preproc_if')),
|
|
1417
1420
|
alias(sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef')),
|
|
1418
1421
|
seq($.preproc_call, ','),
|
|
@@ -1485,6 +1488,14 @@ module.exports = Object.assign(
|
|
|
1485
1488
|
|
|
1486
1489
|
bitfield_clause: ($) => seq(':', $.expression),
|
|
1487
1490
|
|
|
1491
|
+
_enumerator_macro: ($) => seq(alias($._enumerator_macro_call, $.call_expression), optional(',')),
|
|
1492
|
+
|
|
1493
|
+
_enumerator_macro_call: ($) =>
|
|
1494
|
+
seq(
|
|
1495
|
+
field('function', $.identifier),
|
|
1496
|
+
field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
|
|
1497
|
+
),
|
|
1498
|
+
|
|
1488
1499
|
enumerator: ($) => seq(field('name', $.identifier), optional(seq('=', field('value', $.expression)))),
|
|
1489
1500
|
|
|
1490
1501
|
variadic_parameter: () => '...',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-c",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "C grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"c",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
19
|
"types/*",
|
|
20
|
-
"queries/*.scm",
|
|
21
20
|
"src/node-types.json",
|
|
22
21
|
"tree-sitter.json",
|
|
23
22
|
"*.wasm",
|
|
@@ -55,19 +54,19 @@
|
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@tsconfig/bun": "1.0.11",
|
|
58
|
-
"@types/bun": "1.4.
|
|
57
|
+
"@types/bun": "1.4.4",
|
|
59
58
|
"@vitest/browser-playwright": "5.0.5",
|
|
60
59
|
"@willbooster/oxlint-config": "1.4.9",
|
|
61
|
-
"@willbooster/wb": "
|
|
60
|
+
"@willbooster/wb": "23.0.2",
|
|
62
61
|
"@willbooster/web-tree-sitter": "15.0.3",
|
|
63
62
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
64
63
|
"lefthook": "2.2.2",
|
|
65
|
-
"oxlint": "1.
|
|
66
|
-
"oxlint-tsgolint": "7.0.
|
|
64
|
+
"oxlint": "1.89.0",
|
|
65
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
67
66
|
"playwright": "1.64.1",
|
|
68
67
|
"semantic-release": "25.0.9",
|
|
69
68
|
"vitest": "5.0.5",
|
|
70
|
-
"wrangler": "4.
|
|
69
|
+
"wrangler": "4.152.0"
|
|
71
70
|
},
|
|
72
71
|
"peerDependencies": {
|
|
73
72
|
"@willbooster/web-tree-sitter": "^15.0.3"
|
package/src/node-types.json
CHANGED
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
"c",
|
|
11
11
|
"h"
|
|
12
12
|
],
|
|
13
|
-
"highlights": "queries/highlights.scm",
|
|
14
|
-
"tags": "queries/tags.scm",
|
|
15
13
|
"injection-regex": "^(c|h)$",
|
|
16
14
|
"external-files": [
|
|
17
15
|
"src/pragma.h",
|
|
@@ -24,7 +22,7 @@
|
|
|
24
22
|
}
|
|
25
23
|
],
|
|
26
24
|
"metadata": {
|
|
27
|
-
"version": "
|
|
25
|
+
"version": "22.0.0",
|
|
28
26
|
"license": "MIT",
|
|
29
27
|
"description": "C grammar for tree-sitter",
|
|
30
28
|
"authors": [
|
package/queries/highlights.scm
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
(identifier) @variable
|
|
2
|
-
|
|
3
|
-
((identifier) @constant
|
|
4
|
-
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
|
|
5
|
-
|
|
6
|
-
((storage_class_specifier) @keyword
|
|
7
|
-
(#eq? @keyword "auto"))
|
|
8
|
-
"_Countof" @keyword
|
|
9
|
-
"_Defer" @keyword
|
|
10
|
-
"_Generic" @keyword
|
|
11
|
-
"_Thread_local" @keyword
|
|
12
|
-
"break" @keyword
|
|
13
|
-
"case" @keyword
|
|
14
|
-
"const" @keyword
|
|
15
|
-
"continue" @keyword
|
|
16
|
-
"default" @keyword
|
|
17
|
-
"do" @keyword
|
|
18
|
-
"else" @keyword
|
|
19
|
-
"enum" @keyword
|
|
20
|
-
"extern" @keyword
|
|
21
|
-
"for" @keyword
|
|
22
|
-
"goto" @keyword
|
|
23
|
-
"if" @keyword
|
|
24
|
-
"inline" @keyword
|
|
25
|
-
"return" @keyword
|
|
26
|
-
"sizeof" @keyword
|
|
27
|
-
"static" @keyword
|
|
28
|
-
"struct" @keyword
|
|
29
|
-
"switch" @keyword
|
|
30
|
-
"typedef" @keyword
|
|
31
|
-
"union" @keyword
|
|
32
|
-
"volatile" @keyword
|
|
33
|
-
"while" @keyword
|
|
34
|
-
|
|
35
|
-
"#define" @keyword
|
|
36
|
-
"#elif" @keyword
|
|
37
|
-
"#elifdef" @keyword
|
|
38
|
-
"#elifndef" @keyword
|
|
39
|
-
"#else" @keyword
|
|
40
|
-
"#endif" @keyword
|
|
41
|
-
"#if" @keyword
|
|
42
|
-
"#ifdef" @keyword
|
|
43
|
-
"#ifndef" @keyword
|
|
44
|
-
"#include" @keyword
|
|
45
|
-
(preproc_directive) @keyword
|
|
46
|
-
|
|
47
|
-
"--" @operator
|
|
48
|
-
"-" @operator
|
|
49
|
-
"-=" @operator
|
|
50
|
-
"->" @operator
|
|
51
|
-
"=" @operator
|
|
52
|
-
"!=" @operator
|
|
53
|
-
"*" @operator
|
|
54
|
-
"&" @operator
|
|
55
|
-
"&&" @operator
|
|
56
|
-
"+" @operator
|
|
57
|
-
"++" @operator
|
|
58
|
-
"+=" @operator
|
|
59
|
-
"<" @operator
|
|
60
|
-
"==" @operator
|
|
61
|
-
">" @operator
|
|
62
|
-
"||" @operator
|
|
63
|
-
"*=" @operator
|
|
64
|
-
"/=" @operator
|
|
65
|
-
"%=" @operator
|
|
66
|
-
"<<=" @operator
|
|
67
|
-
">>=" @operator
|
|
68
|
-
"&=" @operator
|
|
69
|
-
"|=" @operator
|
|
70
|
-
"^=" @operator
|
|
71
|
-
"/" @operator
|
|
72
|
-
"%" @operator
|
|
73
|
-
"<=" @operator
|
|
74
|
-
">=" @operator
|
|
75
|
-
"<<" @operator
|
|
76
|
-
">>" @operator
|
|
77
|
-
"|" @operator
|
|
78
|
-
"^" @operator
|
|
79
|
-
"~" @operator
|
|
80
|
-
"!" @operator
|
|
81
|
-
|
|
82
|
-
(conditional_expression
|
|
83
|
-
["?" ":"] @operator)
|
|
84
|
-
|
|
85
|
-
(field_expression
|
|
86
|
-
operator: "." @operator)
|
|
87
|
-
|
|
88
|
-
(field_designator "." @delimiter)
|
|
89
|
-
";" @delimiter
|
|
90
|
-
|
|
91
|
-
(string_literal) @string
|
|
92
|
-
(raw_string_literal) @string
|
|
93
|
-
(system_lib_string) @string
|
|
94
|
-
|
|
95
|
-
(null) @constant
|
|
96
|
-
(number_literal) @number
|
|
97
|
-
(char_literal) @number
|
|
98
|
-
|
|
99
|
-
(field_identifier) @property
|
|
100
|
-
(statement_identifier) @label
|
|
101
|
-
(type_identifier) @type
|
|
102
|
-
(primitive_type) @type
|
|
103
|
-
(sized_type_specifier) @type
|
|
104
|
-
|
|
105
|
-
(call_expression
|
|
106
|
-
function: (identifier) @function)
|
|
107
|
-
(call_expression
|
|
108
|
-
function: (field_expression
|
|
109
|
-
field: (field_identifier) @function))
|
|
110
|
-
(function_declarator
|
|
111
|
-
declarator: (identifier) @function)
|
|
112
|
-
(preproc_function_def
|
|
113
|
-
name: (identifier) @function.special)
|
|
114
|
-
|
|
115
|
-
(comment) @comment
|
|
116
|
-
|
|
117
|
-
(typeof_specifier
|
|
118
|
-
["typeof" "typeof_unqual" "__typeof__" "__typeof" "__typeof_unqual" "__typeof_unqual__"] @keyword)
|
|
119
|
-
(bit_int_specifier "_BitInt" @type)
|
|
120
|
-
(pragma_operator) @keyword
|
|
121
|
-
|
|
122
|
-
(va_arg_expression ["va_arg" "__builtin_va_arg"] @keyword)
|
package/queries/tags.scm
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
(struct_specifier name: (type_identifier) @name body:(_)) @definition.class
|
|
2
|
-
|
|
3
|
-
(declaration type: (union_specifier name: (type_identifier) @name)) @definition.class
|
|
4
|
-
|
|
5
|
-
(function_declarator declarator: (identifier) @name) @definition.function
|
|
6
|
-
|
|
7
|
-
(type_definition declarator: (type_identifier) @name) @definition.type
|
|
8
|
-
|
|
9
|
-
(enum_specifier name: (type_identifier) @name) @definition.type
|