@willbooster/tree-sitter-cpp 0.0.0-placeholder.0 → 1.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 ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Max Brunsfeld
4
+ Copyright (c) 2026 WillBooster Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,112 @@
1
1
  # @willbooster/tree-sitter-cpp
2
2
 
3
- This version is a placeholder that reserves the package name so that releases can be published from GitHub Actions with trusted publishing. Use 1.0.0 or later.
3
+ [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-cpp.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-cpp)
4
+ [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-cpp.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-cpp)
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
+ [![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
+ [![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)
9
+ [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-cpp.svg)](https://crates.io/crates/willbooster-tree-sitter-cpp)
10
+
11
+ C++ grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
12
+ [tree-sitter/tree-sitter-cpp](https://github.com/tree-sitter/tree-sitter-cpp). We are grateful
13
+ to its authors and contributors. This is not an official release of that project.
14
+
15
+ This fork fixes parsing bugs and raises conformance with the ISO C++ standard ([working draft](https://eel.is/c++draft/)).
16
+
17
+ ## Usage
18
+
19
+ The npm package ships `tree-sitter-cpp.wasm` for
20
+ [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
21
+ browsers, and Cloudflare Workers. Install both:
22
+
23
+ ```sh
24
+ npm install @willbooster/tree-sitter-cpp @willbooster/web-tree-sitter
25
+ ```
26
+
27
+ In Node.js and Bun, load the `.wasm` file from its path:
28
+
29
+ ```js
30
+ import { fileURLToPath } from 'node:url';
31
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
32
+
33
+ await Parser.init();
34
+ const parser = new Parser();
35
+ const wasmPath = fileURLToPath(import.meta.resolve('@willbooster/tree-sitter-cpp/tree-sitter-cpp.wasm'));
36
+ parser.setLanguage(await Language.load(wasmPath));
37
+ const tree = parser.parse('int main() {}\n');
38
+ ```
39
+
40
+ In browsers, serve both `.wasm` files and load them by URL. With Vite:
41
+
42
+ ```js
43
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
44
+ import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
45
+ import cppUrl from '@willbooster/tree-sitter-cpp/tree-sitter-cpp.wasm?url';
46
+
47
+ await Parser.init({ locateFile: () => runtimeUrl });
48
+ const parser = new Parser();
49
+ parser.setLanguage(await Language.load(cppUrl));
50
+ ```
51
+
52
+ In Cloudflare Workers, which do not allow compiling Wasm at run time, import both `.wasm` files as modules:
53
+
54
+ ```js
55
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
56
+ import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
57
+ import cpp from '@willbooster/tree-sitter-cpp/tree-sitter-cpp.wasm';
58
+
59
+ await Parser.init({ wasmModule: runtime });
60
+ const parser = new Parser();
61
+ parser.setLanguage(await Language.load(cpp));
62
+ ```
63
+
64
+ The package also ships the node types in `src/node-types.json`.
65
+
66
+ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-cpp):
67
+
68
+ ```toml
69
+ [dependencies]
70
+ tree-sitter = "0.27"
71
+ tree-sitter-cpp = { package = "willbooster-tree-sitter-cpp", version = "1" }
72
+ ```
73
+
74
+ ```rust
75
+ let mut parser = tree_sitter::Parser::new();
76
+ parser.set_language(&tree_sitter_cpp::LANGUAGE.into())?;
77
+ ```
78
+
79
+ ## Development
80
+
81
+ ```sh
82
+ mise install
83
+ bun install --frozen-lockfile
84
+ bun run build/ci
85
+ bun run test
86
+ script/parse-examples
87
+ cargo test --locked
88
+ ```
89
+
90
+ `bun run test` runs:
91
+
92
+ - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
93
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
94
+ reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
95
+ `TREE_SITTER_EDITS` run other or more edits;
96
+ - a check that the real-world C++ files in `examples/`, the checked-in ones and those of the cloned repositories,
97
+ fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example repositories are pinned to commits in
98
+ `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
99
+ it; review its diff before committing;
100
+ - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
101
+ linear time, since consumers parse files while they are being edited. It loads the Wasm build through
102
+ @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
103
+ - checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
104
+ Node.js compatibility (`test/unit/workers.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
105
+
106
+ CI also runs these tests on Linux arm64 and macOS, where the parser and scanner are compiled natively against each platform's C library, and fuzzes the parser with libFuzzer and sanitizers
107
+ (`.github/workflows/robustness.yml`).
108
+
109
+ ### References
110
+
111
+ - [Hyperlinked C++ BNF Grammar](http://www.nongnu.org/hcb/)
112
+ - [EBNF Syntax: C++](http://www.externsoft.ch/download/cpp-iso.html)
package/package.json CHANGED
@@ -1,13 +1,74 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-cpp",
3
- "version": "0.0.0-placeholder.0",
4
- "description": "Placeholder for WillBooster's fork of tree-sitter-cpp; the first release is 1.0.0",
3
+ "version": "1.0.0",
4
+ "description": "C++ grammar for tree-sitter",
5
+ "keywords": [
6
+ "incremental",
7
+ "parsing",
8
+ "tree-sitter",
9
+ "cpp"
10
+ ],
5
11
  "repository": {
6
12
  "type": "git",
7
13
  "url": "git+https://github.com/WillBooster/tree-sitter-cpp.git"
8
14
  },
9
15
  "license": "MIT",
10
16
  "author": "WillBooster Inc.",
17
+ "files": [
18
+ "tree-sitter.json",
19
+ "src/node-types.json",
20
+ "*.wasm"
21
+ ],
22
+ "scripts": {
23
+ "build-wasm": "tree-sitter build --wasm",
24
+ "build/ci": "tree-sitter generate && tree-sitter build --wasm",
25
+ "cleanup": "bun wb lint --fix --format",
26
+ "format": "bun wb lint --format",
27
+ "lint": "bun wb lint",
28
+ "lint-fix": "bun wb lint --fix",
29
+ "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
30
+ "release": "wb release",
31
+ "prestart": "bun run build-wasm",
32
+ "start": "tree-sitter playground",
33
+ "test": "bun wb test",
34
+ "test/ci": "bun wb test-on-ci",
35
+ "test/ci-setup": "bun playwright install --with-deps chromium",
36
+ "typecheck": "bun wb typecheck",
37
+ "verify": "bun wb verify",
38
+ "verify-full": "bun wb verify --full"
39
+ },
40
+ "devDependencies": {
41
+ "@semantic-release/exec": "7.1.0",
42
+ "@tsconfig/bun": "1.0.11",
43
+ "@types/bun": "1.4.2",
44
+ "@vitest/browser-playwright": "5.0.1",
45
+ "@willbooster/oxfmt-config": "1.2.2",
46
+ "@willbooster/oxlint-config": "1.4.8",
47
+ "@willbooster/wb": "22.11.5",
48
+ "@willbooster/web-tree-sitter": "1.0.0",
49
+ "conventional-changelog-conventionalcommits": "10.4.0",
50
+ "lefthook": "2.1.14",
51
+ "oxfmt": "0.70.0",
52
+ "oxlint": "1.85.0",
53
+ "oxlint-tsgolint": "7.0.2002",
54
+ "playwright": "1.63.0",
55
+ "semantic-release": "25.0.9",
56
+ "sort-package-json": "4.0.0",
57
+ "tree-sitter-c": "0.24.1",
58
+ "tree-sitter-cli": "0.27.0",
59
+ "typescript": "7.0.2",
60
+ "vite": "8.3.0",
61
+ "vitest": "5.0.1",
62
+ "wrangler": "4.136.2"
63
+ },
64
+ "peerDependencies": {
65
+ "@willbooster/web-tree-sitter": "^1.0.0"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@willbooster/web-tree-sitter": {
69
+ "optional": true
70
+ }
71
+ },
11
72
  "publishConfig": {
12
73
  "access": "public",
13
74
  "registry": "https://registry.npmjs.org/"