@willbooster/tree-sitter-cpp 20.0.3 → 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 -10
- package/package.json +7 -8
- package/tree-sitter-cpp.wasm +0 -0
- package/tree-sitter.json +1 -7
- package/queries/c/highlights.scm +0 -119
- package/queries/highlights.scm +0 -101
- package/queries/injections.scm +0 -3
- package/queries/tags.scm +0 -15
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-cpp/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-cpp/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-cpp)
|
|
10
10
|
|
|
11
11
|
C++ grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -38,6 +38,13 @@ evaluation and header inclusion are left to a preprocessor. Name lookup, type ch
|
|
|
38
38
|
are left to a compiler. In ambiguous declaration and expression syntax, the chosen tree can therefore differ from
|
|
39
39
|
the compiler's interpretation.
|
|
40
40
|
|
|
41
|
+
## Support Scope
|
|
42
|
+
|
|
43
|
+
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
44
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
|
|
45
|
+
but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
46
|
+
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
47
|
+
|
|
41
48
|
## Usage
|
|
42
49
|
|
|
43
50
|
The npm package ships `tree-sitter-cpp.wasm` for
|
|
@@ -87,8 +94,7 @@ const parser = new Parser();
|
|
|
87
94
|
parser.setLanguage(await Language.load(cpp));
|
|
88
95
|
```
|
|
89
96
|
|
|
90
|
-
The package also ships the node types in `src/node-types.json
|
|
91
|
-
grammar's in `queries/` and, in `queries/c/`, the highlights of the C grammar it extends.
|
|
97
|
+
The package also ships the node types in `src/node-types.json`.
|
|
92
98
|
|
|
93
99
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-cpp) and on
|
|
94
100
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
@@ -104,7 +110,7 @@ let mut parser = tree_sitter::Parser::new();
|
|
|
104
110
|
parser.set_language(&tree_sitter_cpp::LANGUAGE.into())?;
|
|
105
111
|
```
|
|
106
112
|
|
|
107
|
-
The crate ships the same `tree-sitter.json`
|
|
113
|
+
The crate ships the same `tree-sitter.json` as the npm package.
|
|
108
114
|
|
|
109
115
|
## Development
|
|
110
116
|
|
|
@@ -133,9 +139,6 @@ and the release build regenerate the parsers before compiling them.
|
|
|
133
139
|
`bun run test` runs:
|
|
134
140
|
|
|
135
141
|
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
136
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
137
|
-
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
|
|
138
|
-
`TREE_SITTER_EDITS` run other or more edits;
|
|
139
142
|
- a check that the real-world C++ files in `examples/`, the checked-in ones and those of the cloned repositories,
|
|
140
143
|
fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
|
|
141
144
|
repositories are pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that
|
|
@@ -147,9 +150,9 @@ and the release build regenerate the parsers before compiling them.
|
|
|
147
150
|
parameter is expected in parameter lists, so that `long(n)(sizeof(b));` stays an initialization, and that the
|
|
148
151
|
keyword-led arguments that make `Foo* p(nullptr);` a variable start only with such keywords or `this`, which starts
|
|
149
152
|
a parameter only when a declaration follows it;
|
|
150
|
-
- a check (`test/unit/
|
|
151
|
-
|
|
152
|
-
@willbooster/tree-sitter-c.
|
|
153
|
+
- a check (`test/unit/grammarPackage.test.ts`) that `tree-sitter.json` is published in the npm package and the crate,
|
|
154
|
+
that the scanner headers are published in the crate, and that the vendored scanner headers match the installed
|
|
155
|
+
@willbooster/tree-sitter-c. After updating that dependency, run `script/copy-c-scanner`.
|
|
153
156
|
The scanner headers are verbatim copies from that package; their generator paths refer to the C repository.
|
|
154
157
|
Review the C scanner dispatch and external-token order against `src/scanner.c` when updating the dependency;
|
|
155
158
|
- a check (`test/unit/runtimeVersion.test.ts`) that `@willbooster/web-tree-sitter` in `package.json` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-cpp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "C++ grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cpp",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"url": "git+https://github.com/WillBooster/tree-sitter-cpp.git"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"queries/**/*.scm",
|
|
19
18
|
"tree-sitter.json",
|
|
20
19
|
"src/node-types.json",
|
|
21
20
|
"*.wasm"
|
|
@@ -45,21 +44,21 @@
|
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@tsconfig/bun": "1.0.11",
|
|
48
|
-
"@types/bun": "1.4.
|
|
47
|
+
"@types/bun": "1.4.4",
|
|
49
48
|
"@vitest/browser-playwright": "5.0.5",
|
|
50
49
|
"@willbooster/oxlint-config": "1.4.9",
|
|
51
50
|
"@willbooster/tree-sitter-c": "18.1.0",
|
|
52
|
-
"@willbooster/wb": "
|
|
51
|
+
"@willbooster/wb": "23.0.2",
|
|
53
52
|
"@willbooster/web-tree-sitter": "15.0.0",
|
|
54
53
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
55
54
|
"lefthook": "2.2.2",
|
|
56
|
-
"oxlint": "1.
|
|
57
|
-
"oxlint-tsgolint": "7.0.
|
|
55
|
+
"oxlint": "1.89.0",
|
|
56
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
58
57
|
"playwright": "1.64.1",
|
|
59
58
|
"semantic-release": "25.0.9",
|
|
60
|
-
"vite": "8.3.
|
|
59
|
+
"vite": "8.3.5",
|
|
61
60
|
"vitest": "5.0.5",
|
|
62
|
-
"wrangler": "4.
|
|
61
|
+
"wrangler": "4.152.0"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
65
64
|
"@willbooster/web-tree-sitter": "^15.0.0"
|
package/tree-sitter-cpp.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -14,12 +14,6 @@
|
|
|
14
14
|
"hxx",
|
|
15
15
|
"h"
|
|
16
16
|
],
|
|
17
|
-
"highlights": [
|
|
18
|
-
"queries/c/highlights.scm",
|
|
19
|
-
"queries/highlights.scm"
|
|
20
|
-
],
|
|
21
|
-
"injections": "queries/injections.scm",
|
|
22
|
-
"tags": "queries/tags.scm",
|
|
23
17
|
"injection-regex": "^(cc|cpp)$",
|
|
24
18
|
"external-files": [
|
|
25
19
|
"src/pragma.h",
|
|
@@ -31,7 +25,7 @@
|
|
|
31
25
|
}
|
|
32
26
|
],
|
|
33
27
|
"metadata": {
|
|
34
|
-
"version": "
|
|
28
|
+
"version": "22.0.0",
|
|
35
29
|
"license": "MIT",
|
|
36
30
|
"description": "C++ grammar for tree-sitter",
|
|
37
31
|
"authors": [
|
package/queries/c/highlights.scm
DELETED
|
@@ -1,119 +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
|
-
"_Generic" @keyword
|
|
9
|
-
"_Thread_local" @keyword
|
|
10
|
-
"break" @keyword
|
|
11
|
-
"case" @keyword
|
|
12
|
-
"const" @keyword
|
|
13
|
-
"continue" @keyword
|
|
14
|
-
"default" @keyword
|
|
15
|
-
"do" @keyword
|
|
16
|
-
"else" @keyword
|
|
17
|
-
"enum" @keyword
|
|
18
|
-
"extern" @keyword
|
|
19
|
-
"for" @keyword
|
|
20
|
-
"goto" @keyword
|
|
21
|
-
"if" @keyword
|
|
22
|
-
"inline" @keyword
|
|
23
|
-
"return" @keyword
|
|
24
|
-
"sizeof" @keyword
|
|
25
|
-
"static" @keyword
|
|
26
|
-
"struct" @keyword
|
|
27
|
-
"switch" @keyword
|
|
28
|
-
"typedef" @keyword
|
|
29
|
-
"union" @keyword
|
|
30
|
-
"volatile" @keyword
|
|
31
|
-
"while" @keyword
|
|
32
|
-
|
|
33
|
-
"#define" @keyword
|
|
34
|
-
"#elif" @keyword
|
|
35
|
-
"#elifdef" @keyword
|
|
36
|
-
"#elifndef" @keyword
|
|
37
|
-
"#else" @keyword
|
|
38
|
-
"#endif" @keyword
|
|
39
|
-
"#if" @keyword
|
|
40
|
-
"#ifdef" @keyword
|
|
41
|
-
"#ifndef" @keyword
|
|
42
|
-
"#include" @keyword
|
|
43
|
-
(preproc_directive) @keyword
|
|
44
|
-
|
|
45
|
-
"--" @operator
|
|
46
|
-
"-" @operator
|
|
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
|
-
|
|
80
|
-
(conditional_expression
|
|
81
|
-
["?" ":"] @operator)
|
|
82
|
-
|
|
83
|
-
(field_expression
|
|
84
|
-
operator: "." @operator)
|
|
85
|
-
|
|
86
|
-
(field_designator "." @delimiter)
|
|
87
|
-
";" @delimiter
|
|
88
|
-
|
|
89
|
-
(string_literal) @string
|
|
90
|
-
(system_lib_string) @string
|
|
91
|
-
|
|
92
|
-
(null) @constant
|
|
93
|
-
(number_literal) @number
|
|
94
|
-
(char_literal) @number
|
|
95
|
-
|
|
96
|
-
(field_identifier) @property
|
|
97
|
-
(statement_identifier) @label
|
|
98
|
-
(type_identifier) @type
|
|
99
|
-
(primitive_type) @type
|
|
100
|
-
(sized_type_specifier) @type
|
|
101
|
-
|
|
102
|
-
(call_expression
|
|
103
|
-
function: (identifier) @function)
|
|
104
|
-
(call_expression
|
|
105
|
-
function: (field_expression
|
|
106
|
-
field: (field_identifier) @function))
|
|
107
|
-
(function_declarator
|
|
108
|
-
declarator: (identifier) @function)
|
|
109
|
-
(preproc_function_def
|
|
110
|
-
name: (identifier) @function.special)
|
|
111
|
-
|
|
112
|
-
(comment) @comment
|
|
113
|
-
|
|
114
|
-
(typeof_specifier
|
|
115
|
-
["typeof" "typeof_unqual" "__typeof__" "__typeof" "__typeof_unqual" "__typeof_unqual__"] @keyword)
|
|
116
|
-
(bit_int_specifier "_BitInt" @type)
|
|
117
|
-
(pragma_operator) @keyword
|
|
118
|
-
|
|
119
|
-
(va_arg_expression ["va_arg" "__builtin_va_arg"] @keyword)
|
package/queries/highlights.scm
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
; inherits: c
|
|
2
|
-
|
|
3
|
-
; Functions
|
|
4
|
-
|
|
5
|
-
(call_expression
|
|
6
|
-
function: (qualified_identifier
|
|
7
|
-
name: (identifier) @function))
|
|
8
|
-
|
|
9
|
-
(template_function
|
|
10
|
-
name: (identifier) @function)
|
|
11
|
-
|
|
12
|
-
(template_method
|
|
13
|
-
name: (field_identifier) @function)
|
|
14
|
-
|
|
15
|
-
(template_function
|
|
16
|
-
name: (identifier) @function)
|
|
17
|
-
|
|
18
|
-
(function_declarator
|
|
19
|
-
declarator: (qualified_identifier
|
|
20
|
-
name: (identifier) @function))
|
|
21
|
-
|
|
22
|
-
(function_declarator
|
|
23
|
-
declarator: (field_identifier) @function)
|
|
24
|
-
|
|
25
|
-
(operator_argument "." @operator)
|
|
26
|
-
|
|
27
|
-
; Types
|
|
28
|
-
|
|
29
|
-
((namespace_identifier) @type
|
|
30
|
-
(#match? @type "^[A-Z]"))
|
|
31
|
-
|
|
32
|
-
(auto) @type
|
|
33
|
-
|
|
34
|
-
; Constants
|
|
35
|
-
|
|
36
|
-
(this) @variable.builtin
|
|
37
|
-
(null "nullptr" @constant)
|
|
38
|
-
|
|
39
|
-
; Modules
|
|
40
|
-
(module_name
|
|
41
|
-
(identifier) @module)
|
|
42
|
-
|
|
43
|
-
(module_name "." @delimiter)
|
|
44
|
-
|
|
45
|
-
; Keywords
|
|
46
|
-
|
|
47
|
-
[
|
|
48
|
-
"catch"
|
|
49
|
-
"class"
|
|
50
|
-
"co_await"
|
|
51
|
-
"co_return"
|
|
52
|
-
"co_yield"
|
|
53
|
-
"constexpr"
|
|
54
|
-
"constinit"
|
|
55
|
-
"consteval"
|
|
56
|
-
"delete"
|
|
57
|
-
"explicit"
|
|
58
|
-
"final"
|
|
59
|
-
"friend"
|
|
60
|
-
"mutable"
|
|
61
|
-
"namespace"
|
|
62
|
-
"noexcept"
|
|
63
|
-
"new"
|
|
64
|
-
"override"
|
|
65
|
-
"pre"
|
|
66
|
-
"post"
|
|
67
|
-
"private"
|
|
68
|
-
"protected"
|
|
69
|
-
"public"
|
|
70
|
-
"template"
|
|
71
|
-
"throw"
|
|
72
|
-
"try"
|
|
73
|
-
"typename"
|
|
74
|
-
"using"
|
|
75
|
-
"concept"
|
|
76
|
-
"requires"
|
|
77
|
-
"virtual"
|
|
78
|
-
"import"
|
|
79
|
-
"export"
|
|
80
|
-
"module"
|
|
81
|
-
] @keyword
|
|
82
|
-
|
|
83
|
-
[(operator_name "operator" @keyword)
|
|
84
|
-
(operator_cast "operator" @keyword)]
|
|
85
|
-
|
|
86
|
-
; Operators
|
|
87
|
-
|
|
88
|
-
[
|
|
89
|
-
".*" "->*" "<=>"
|
|
90
|
-
"and" "and_eq" "bitand" "bitor" "compl" "not" "not_eq" "or" "or_eq" "xor" "xor_eq"
|
|
91
|
-
] @operator
|
|
92
|
-
|
|
93
|
-
; Strings
|
|
94
|
-
|
|
95
|
-
(raw_string_literal) @string
|
|
96
|
-
|
|
97
|
-
["static_cast" "dynamic_cast" "const_cast" "reinterpret_cast" "typeid"] @keyword
|
|
98
|
-
|
|
99
|
-
((call_expression
|
|
100
|
-
function: (identifier) @keyword)
|
|
101
|
-
(#eq? @keyword "noexcept"))
|
package/queries/injections.scm
DELETED
package/queries/tags.scm
DELETED
|
@@ -1,15 +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
|
-
(function_declarator declarator: (field_identifier) @name) @definition.function
|
|
8
|
-
|
|
9
|
-
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @local.scope name: (identifier) @name)) @definition.method
|
|
10
|
-
|
|
11
|
-
(type_definition declarator: (type_identifier) @name) @definition.type
|
|
12
|
-
|
|
13
|
-
(enum_specifier name: (type_identifier) @name) @definition.type
|
|
14
|
-
|
|
15
|
-
(class_specifier name: (type_identifier) @name) @definition.class
|