@willbooster/tree-sitter-cpp 1.2.2 → 1.2.4

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-cpp/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-cpp/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-cpp/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-cpp/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.26.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.28.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-cpp.svg)](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
@@ -62,7 +62,8 @@ const parser = new Parser();
62
62
  parser.setLanguage(await Language.load(cpp));
63
63
  ```
64
64
 
65
- The package also ships the node types in `src/node-types.json`.
65
+ The package also ships the node types in `src/node-types.json`, and the queries that `tree-sitter.json` lists: this
66
+ grammar's in `queries/` and, in `queries/c/`, the highlights of the C grammar it extends.
66
67
 
67
68
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-cpp) and on
68
69
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -80,6 +81,8 @@ let mut parser = tree_sitter::Parser::new();
80
81
  parser.set_language(&tree_sitter_cpp::LANGUAGE.into())?;
81
82
  ```
82
83
 
84
+ The crate ships the same `tree-sitter.json` and query files as the npm package.
85
+
83
86
  ## Development
84
87
 
85
88
  ```sh
@@ -91,11 +94,17 @@ script/parse-examples
91
94
  cargo test --locked
92
95
  ```
93
96
 
97
+ The scripts and tests generate, build, test, and parse with `script/tree-sitter`, the tree-sitter CLI of the
98
+ WillBooster/tree-sitter runtime version locked in `Cargo.lock`, since the generator and the runtime of upstream's CLI are
99
+ not the ones this package ships with. Its first run downloads that CLI from the runtime's GitHub Release, or builds it
100
+ with `cargo` (whose build runs the CMake that `mise.toml` pins) when the download fails or the release has no binary
101
+ that runs here. Run other CLI commands through it as well (e.g. `script/tree-sitter parse file.cpp`).
102
+
94
103
  `bun run test` runs:
95
104
 
96
105
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
97
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
98
- reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
106
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
107
+ edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
99
108
  `TREE_SITTER_EDITS` run other or more edits;
100
109
  - a check that the real-world C++ files in `examples/`, the checked-in ones and those of the cloned repositories,
101
110
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
@@ -105,11 +114,15 @@ cargo test --locked
105
114
  time, since consumers parse files while they are being edited. It loads the Wasm build through
106
115
  @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
107
116
  - a check (`test/unit/expressionKeywordParameter.test.ts`) that every keyword that can start an expression but not a
108
- parameter is expected in the parameters of the function declarators that compete with a direct initialization, so
109
- that `long(n)(sizeof(b));` stays an initialization;
117
+ parameter is expected in parameter lists, so that `long(n)(sizeof(b));` stays an initialization, and that the
118
+ keyword-led arguments that make `Foo* p(nullptr);` a variable start only with such keywords or `this`, which starts
119
+ a parameter only when a declaration follows it;
120
+ - a check (`test/unit/queries.test.ts`) that the queries `tree-sitter.json` lists compile against the grammar, are
121
+ published in the npm package and the crate, and that `queries/c/` matches the queries of the installed
122
+ @willbooster/tree-sitter-c; after updating that dependency, `script/copy-c-queries` refreshes the copy;
110
123
  - a check (`test/unit/runtimeVersion.test.ts`) that `@willbooster/web-tree-sitter` in `package.json` and
111
124
  `willbooster-tree-sitter` in `Cargo.lock` are the same version, since the Wasm tests run on the former and the Rust
112
- tests and the fuzzer on the latter;
125
+ tests, the fuzzer, and the CLI on the latter;
113
126
  - checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
114
127
  Node.js compatibility (`test/unit/workers.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
115
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-cpp",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "C++ grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -15,13 +15,14 @@
15
15
  "license": "MIT",
16
16
  "author": "WillBooster Inc.",
17
17
  "files": [
18
+ "queries/**/*.scm",
18
19
  "tree-sitter.json",
19
20
  "src/node-types.json",
20
21
  "*.wasm"
21
22
  ],
22
23
  "scripts": {
23
- "build-wasm": "tree-sitter build --wasm",
24
- "build/ci": "tree-sitter generate && tree-sitter build --wasm",
24
+ "build-wasm": "script/tree-sitter build --wasm",
25
+ "build/ci": "script/tree-sitter generate && script/tree-sitter build --wasm",
25
26
  "cleanup": "bun wb lint --fix --format",
26
27
  "format": "bun wb lint --format",
27
28
  "lint": "bun wb lint",
@@ -29,7 +30,7 @@
29
30
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
30
31
  "release": "wb release",
31
32
  "prestart": "bun run build-wasm",
32
- "start": "tree-sitter playground",
33
+ "start": "script/tree-sitter playground",
33
34
  "test": "bun wb test",
34
35
  "test/ci": "bun wb test-on-ci",
35
36
  "test/ci-setup": "bun playwright install --with-deps chromium",
@@ -43,14 +44,14 @@
43
44
  "@vitest/browser-playwright": "5.0.1",
44
45
  "@willbooster/oxfmt-config": "1.2.2",
45
46
  "@willbooster/oxlint-config": "1.4.8",
46
- "@willbooster/tree-sitter-c": "1.1.4",
47
- "@willbooster/wb": "22.13.1",
48
- "@willbooster/web-tree-sitter": "1.0.8",
47
+ "@willbooster/tree-sitter-c": "1.1.6",
48
+ "@willbooster/wb": "22.13.2",
49
+ "@willbooster/web-tree-sitter": "1.0.17",
49
50
  "conventional-changelog-conventionalcommits": "10.4.0",
50
51
  "lefthook": "2.1.14",
51
52
  "oxfmt": "0.70.0",
52
53
  "oxlint": "1.85.0",
53
- "oxlint-tsgolint": "7.0.2002",
54
+ "oxlint-tsgolint": "7.0.2003",
54
55
  "playwright": "1.63.0",
55
56
  "semantic-release": "25.0.9",
56
57
  "sort-package-json": "4.0.0",
@@ -0,0 +1,81 @@
1
+ (identifier) @variable
2
+
3
+ ((identifier) @constant
4
+ (#match? @constant "^[A-Z][A-Z\\d_]*$"))
5
+
6
+ "break" @keyword
7
+ "case" @keyword
8
+ "const" @keyword
9
+ "continue" @keyword
10
+ "default" @keyword
11
+ "do" @keyword
12
+ "else" @keyword
13
+ "enum" @keyword
14
+ "extern" @keyword
15
+ "for" @keyword
16
+ "if" @keyword
17
+ "inline" @keyword
18
+ "return" @keyword
19
+ "sizeof" @keyword
20
+ "static" @keyword
21
+ "struct" @keyword
22
+ "switch" @keyword
23
+ "typedef" @keyword
24
+ "union" @keyword
25
+ "volatile" @keyword
26
+ "while" @keyword
27
+
28
+ "#define" @keyword
29
+ "#elif" @keyword
30
+ "#else" @keyword
31
+ "#endif" @keyword
32
+ "#if" @keyword
33
+ "#ifdef" @keyword
34
+ "#ifndef" @keyword
35
+ "#include" @keyword
36
+ (preproc_directive) @keyword
37
+
38
+ "--" @operator
39
+ "-" @operator
40
+ "-=" @operator
41
+ "->" @operator
42
+ "=" @operator
43
+ "!=" @operator
44
+ "*" @operator
45
+ "&" @operator
46
+ "&&" @operator
47
+ "+" @operator
48
+ "++" @operator
49
+ "+=" @operator
50
+ "<" @operator
51
+ "==" @operator
52
+ ">" @operator
53
+ "||" @operator
54
+
55
+ "." @delimiter
56
+ ";" @delimiter
57
+
58
+ (string_literal) @string
59
+ (system_lib_string) @string
60
+
61
+ (null) @constant
62
+ (number_literal) @number
63
+ (char_literal) @number
64
+
65
+ (field_identifier) @property
66
+ (statement_identifier) @label
67
+ (type_identifier) @type
68
+ (primitive_type) @type
69
+ (sized_type_specifier) @type
70
+
71
+ (call_expression
72
+ function: (identifier) @function)
73
+ (call_expression
74
+ function: (field_expression
75
+ field: (field_identifier) @function))
76
+ (function_declarator
77
+ declarator: (identifier) @function)
78
+ (preproc_function_def
79
+ name: (identifier) @function.special)
80
+
81
+ (comment) @comment
@@ -0,0 +1,89 @@
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
+ ; Types
26
+
27
+ ((namespace_identifier) @type
28
+ (#match? @type "^[A-Z]"))
29
+
30
+ (auto) @type
31
+
32
+ ; Constants
33
+
34
+ (this) @variable.builtin
35
+ (null "nullptr" @constant)
36
+
37
+ ; Modules
38
+ (module_name
39
+ (identifier) @module)
40
+
41
+ ; Keywords
42
+
43
+ [
44
+ "catch"
45
+ "class"
46
+ "co_await"
47
+ "co_return"
48
+ "co_yield"
49
+ "constexpr"
50
+ "constinit"
51
+ "consteval"
52
+ "delete"
53
+ "explicit"
54
+ "final"
55
+ "friend"
56
+ "mutable"
57
+ "namespace"
58
+ "noexcept"
59
+ "new"
60
+ "override"
61
+ "private"
62
+ "protected"
63
+ "public"
64
+ "template"
65
+ "throw"
66
+ "try"
67
+ "typename"
68
+ "using"
69
+ "concept"
70
+ "requires"
71
+ "virtual"
72
+ "import"
73
+ "export"
74
+ "module"
75
+ ] @keyword
76
+
77
+ ; Strings
78
+
79
+ (raw_string_literal) @string
80
+
81
+ ; Keywords with the shape of a call
82
+
83
+ ((template_function
84
+ name: (identifier) @keyword)
85
+ (#any-of? @keyword "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast"))
86
+
87
+ ((call_expression
88
+ function: (identifier) @keyword)
89
+ (#any-of? @keyword "typeid" "noexcept"))
@@ -0,0 +1,3 @@
1
+ (raw_string_literal
2
+ delimiter: (raw_string_delimiter) @injection.language
3
+ (raw_string_content) @injection.content)
@@ -0,0 +1,15 @@
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
Binary file
package/tree-sitter.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "h"
16
16
  ],
17
17
  "highlights": [
18
- "node_modules/@willbooster/tree-sitter-c/queries/highlights.scm",
18
+ "queries/c/highlights.scm",
19
19
  "queries/highlights.scm"
20
20
  ],
21
21
  "injections": "queries/injections.scm",
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "1.2.2",
27
+ "version": "1.2.4",
28
28
  "license": "MIT",
29
29
  "description": "C++ grammar for tree-sitter",
30
30
  "authors": [