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.1

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.1
File Size Uploaded Provenance Actions
tree_sitter_cpp_ai-0.1.1.tar.gz 4.1 MB With provenance Details for tree_sitter_cpp_ai-0.1.1.tar.gz

Built distributions (wheels)

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

Total release size: 12.7 MB

Release files / tree_sitter_cpp_ai-0.1.1.tar.gz

Download URL tree_sitter_cpp_ai-0.1.1.tar.gz
Size 4.1 MB
Tags Source
SHA-256 checksum
How to use checksums
a7817b7befccd33bcb8d436ae66f5bbe979f6f4897c333b2b088ab02cf9fd9d4
BLAKE2b-256 checksum
How to use checksums
c4c65d608a4071041e24c44e41f65bb40b40fee8ddc49d4fb4f11787af9271ec
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.1-cp310-abi3-win_amd64.whl

Download URL tree_sitter_cpp_ai-0.1.1-cp310-abi3-win_amd64.whl
Size 1.2 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e0f809066a3354570026a9660490faa20c373aa5afeafcea85a394c87adfedcb
BLAKE2b-256 checksum
How to use checksums
ce0b90064e18eb07aa8824645ec2e44c99f5ba659a893b46f7aadfb34afe5cf7
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.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
579e1a84b667c7b4bb3ccfdf1260af610046c16986e46b16ea71ed4ef8a6e93a
BLAKE2b-256 checksum
How to use checksums
ecd80392c9b9a824a7cde31589255fba41987cc92b35bfc3a74fb457edf9dcaf
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.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
2e2cdd6aea3ddce41166f3a1115496c79e0ced95e824d8cd299fe965e35af072
BLAKE2b-256 checksum
How to use checksums
359bb7d12295d8ea1761cabeeb5a1612faac1246b59a91c675a503b5a57e8e3c
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.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
7bcad892cb5fb108bf15d5a14a0696ee081370eecf71bbe2c9cba6cd0dac3625
BLAKE2b-256 checksum
How to use checksums
fb5a9c0942864d410cd9889550ca7332125dbee2dfa10aa6f2549180798a1ad8
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.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
45ec4ed8c7246ed3397551cb0627bb5706b08c6ca2db367a2fc012619d9ac270
BLAKE2b-256 checksum
How to use checksums
3de70897fa2b5334cdfebb8fbc9ed218f104bd64228667a5b755b9577e311905
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.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
b391e5c274b0db7c770144532cc1a07fa0ad7901feeba35bc7501a8b186f516d
BLAKE2b-256 checksum
How to use checksums
6d397fad0c8fab792b72fbc599983632dc156549f700664a1309339e273f4660
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.1-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_cpp_ai-0.1.1-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
bcd03d71e2811129bea51d0b2170c20ba3a2b5364383c31e6d39d62acd4b3705
BLAKE2b-256 checksum
How to use checksums
233e37aec9a373b2f896e6511c8a511dbc7f8412d03e9df2d60cbaca9c1b5002
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.1

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.1.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.1 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