Skip to main content

tree-sitter-cpp-ai

C/C++ grammar for tree-sitter that parses real-world code containing unexpanded macros. It is an AI-developed fork of tree-sitter-cpp, based on upstream commit c009222 with upstream's full history preserved, and it remains a drop-in replacement: the language is still cpp and the C entry point is still tree_sitter_cpp.

Tree-sitter grammars see source before preprocessing, so code like this:

class EXPORT_API Widget : public Base {
public:
    int size() const;
};

DECLARE_HANDLER(OnClick)

int API_CALL compute(int x) {
    LOG_SCOPE(x)
    return x;
}

breaks upstream: Widget becomes a function definition containing an ERROR node, and compute loses statements to missing semicolons. This fork parses the class Widget, the DECLARE_HANDLER invocation and the function compute with its LOG_SCOPE statement. It does this from local syntax alone, with no preprocessor, compiler, macro lists or naming guesses, and labels every recovered region (uncertain_*, macro_*, preproc_inline_conditional) so consumers can tell certified syntax from recovery. See the methodology.

Results

Measured once, for release 0.1.0, on a fresh sample whose file selection was fixed before its first parse: 1,300 first-party files, up to 100 per repository, from 13 public repositories never used to develop the grammar (bitcoin, opencv, protobuf, abseil-cpp, googletest, duckdb, obs-studio, CMake, calculator, serenity, redis, llama.cpp and Marlin), pinned in lab/corpora/fresh.json.

upstream this fork
Files with parse errors 475 (36.5%) 111 (8.5%)
ERROR nodes 4,920 784
MISSING nodes 2,128 148
Bytes inside ERROR regions 675,192 27,131
Error-free files that start failing 0

Every repository improves; the files still containing errors range from 2 (duckdb) to 20 (googletest) per 100. No function disappears from a file that upstream parses without errors. The 237 function spans that do disappear all come from files upstream already misparsed, where text such as ABSL_NAMESPACE_BEGIN namespace x { or class X CV_FINAL : public Base { was read as a function definition; the real functions and constructors appear in their place (320 spans).

That measurement was blind. Its failures then exposed standard syntax that neither upstream nor the fork parsed: GNU attributes after declarators, unnamed bit-fields, GNU case ranges, pointer-to-member typedefs, new const T, delete[] (T*)p, long{1}, T __restrict p and constrained template parameters with type defaults. With those fixed, the same sample has 99 files with errors (7.6%), 753 ERROR and 137 MISSING nodes and 26,921 ERROR-region bytes, with no file newly broken and no error-free tree changed. Because these failures guided the fixes, the sample now also counts as development code.

On the code the grammar was developed against, the gap is wider: lab/corpora/heldout.json, 954 files from ten other repositories that were held out at first and later used for development, goes from 490 to 12 files with errors. Expect results on new code to resemble the fresh sample rather than this one.

Parse time on the fresh sample relative to upstream, as per-thread CPU time with both parsers compiled at -O2:

clean in both (825 files) fixed by this fork (364) errors in both (111) all (1,300)
1.06× 0.90× 0.96× 0.98×

Per-file p95 is 1.03× and incremental reparsing 0.74× (the lab's budgets are ≤1.20× for totals and ≤1.25× for p95 and incremental). Code that already parses cleanly pays about 6% for the extra checks; code the fork repairs is faster because the parser no longer runs error recovery.

Trade-offs and limits

  • Size: the generated src/parser.c is about 71 MB (upstream 26 MB) and the compiled library about 17 MB (upstream 5.6 MB), because certified macro shapes need about 30,000 parse states (upstream about 11,700).
  • Memory: holding parsed trees takes about 18% more than upstream, because tree-sitter stores tokens from an external scanner as full nodes.
  • Trees: node types are a superset of upstream's, and some upstream misparses get different, correct trees, so queries written for upstream may need to handle the new nodes.
  • Remaining errors: template-heavy library headers, test frameworks whose macros take arguments that are not expressions, and code whose syntax only exists after macro expansion. See the methodology's known limits.
  • Status: 0.x and experimental; the tree shape may still change between minor versions.

Usage

The packages are named tree-sitter-cpp-ai so they can be installed next to upstream. For example, in Python:

pip install tree-sitter-cpp-ai
import tree_sitter, tree_sitter_cpp_ai
parser = tree_sitter.Parser(tree_sitter.Language(tree_sitter_cpp_ai.language()))

Laboratory

lab/ contains the tooling used to develop the grammar: Clang-checked fixtures, a regression gate, corpus census and timing against upstream, deterministic GLR parse-work checks, and investigation tools to reduce, anonymize, diff and profile parses.

Source layout

grammar.js extends upstream's grammar; each external token's contract is documented at its declaration in externals. The external scanner is src/scanner.c, which lists every token beside the function that decides it and includes its modules from src/scanner/: lexing.h (characters, words, trivia, literals), words.h (keyword lists), balanced.h (bracket, block and argument scans), conditionals.h (preprocessor conditionals), declarations.h (annotation and macro certification) and raw_strings.h.

License

MIT, as upstream. See LICENSE.

Metadata

Release files for tree-sitter-cpp-ai 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-cpp-ai 0.1.2
File Size Uploaded Provenance Actions
tree_sitter_cpp_ai-0.1.2.tar.gz 4.1 MB With provenance Details for tree_sitter_cpp_ai-0.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-cpp-ai 0.1.2
File Actions
tree_sitter_cpp_ai-0.1.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-win_amd64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details for tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl

Total release size: 12.7 MB

Release files / tree_sitter_cpp_ai-0.1.2.tar.gz

Download URL tree_sitter_cpp_ai-0.1.2.tar.gz
Size 4.1 MB
Tags Source
SHA-256 checksum
How to use checksums
ca668fd6885c6f063f38e0bc9c5980b301659f4e93fb85bb8174c51bb3b50e00
BLAKE2b-256 checksum
How to use checksums
847914b5786e53e3cfadedbdfce45ccd19e54b899c7d978627aa9ab0f5b14e59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-win_amd64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-win_amd64.whl
Size 1.2 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fb5e93893e53fd732fa4d16c5fed96a1e1d4c7f0f07ab043a6a40b861aa78f08
BLAKE2b-256 checksum
How to use checksums
f896e0b4f44e1b867d7847096d4dd6e07c22aa2c20166119bab88224cdfbeb50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
bbb056269fd1138e1dcc9582b3ac9ddd14b6fafb78434c25a621cef35d292687
BLAKE2b-256 checksum
How to use checksums
88583d436dd9ac8faf358fb47b3a3ea0653939261c70f891e7a9fb9331ddd2d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.2 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
5dc93bf9d166529bc99491e0950536da29dec5c6b9d13216556e86ffdbc46104
BLAKE2b-256 checksum
How to use checksums
9b2a3df68ffa690b525fac8ac425abc9373e7b2474788d1fcce8d7f8264205b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
b41d7c597e40390248cf3e63745d3359858d05ed20b31e056620849d37bb06b9
BLAKE2b-256 checksum
How to use checksums
614f81d6ba1d68488fe37155246022287bef8fb5d6447b82b33cbdfca2ef26c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
cbe73686e15531c1dd5e765e70b971748c37dd89d1877acf0820f9c8b55ee8c6
BLAKE2b-256 checksum
How to use checksums
e6a0def6045216b5564b4a5363178d66bf9418e130d413a46f7015283878d00f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3f13958f85c01e586663547db5d8a0112040ce080afd4c0539e3f524f3814022
BLAKE2b-256 checksum
How to use checksums
b34b5992a4a3fb64b9a1b39bb2a6a866e96e9482da9047129324844d773f38ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
792e40d2b6521c702978f39146fa6df2124706be0bf50ffe55fe7766432b116d
BLAKE2b-256 checksum
How to use checksums
4caf156a9e37647f9bc8d2bc00b4fbcaf4362aadc76a97602d792bf1bf3504ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for tree-sitter-cpp-ai 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for tree_sitter_cpp_ai-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

8 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page