tree-sitter-cpp
A fast, incremental C++ grammar for the tree-sitter parsing library
Repository Health
Technical Analysis
tree-sitter-cpp is the official C++ grammar for tree-sitter, the incremental parsing library used by editors and developer tools to build concrete syntax trees. It extends the tree-sitter-c grammar with C++-specific constructs (classes, templates, namespaces, lambdas) and compiles to a generated C parser plus bindings for Rust, Go, Node.js, Python, and Swift.
Editors, linters, and static-analysis tools consume this grammar to get fast, error-tolerant, incremental parsing of C++ source, enabling features like syntax highlighting, code folding, and structural code navigation without needing a full compiler front-end.
What You Get
- A complete, actively maintained C++ grammar definition covering modern C++ syntax (templates, lambdas, namespaces, structured bindings)
- A generated, dependency-free C parser (
parser.c) compiled from the grammar for use in any host language - Official bindings for Rust, Go, Node.js, Python, and Swift so the grammar can be embedded directly in tooling written in those languages
- Highlight and tag queries (
queries/highlights.scm) that map syntax nodes to editor highlighting categories - A corpus of test fixtures (
test/corpus,test/highlight) validating grammar correctness against real C++ code samples
Common Use Cases
- Editor syntax highlighting - power semantic, tree-sitter-based highlighting in editors like Neovim, Helix, and Zed for C++ files
- Code navigation tooling - build ‘jump to definition’ and structural outline features by querying the parsed C++ syntax tree
- Static analysis and linters - traverse the concrete syntax tree to implement custom C++ lint rules without a full compiler
- Language server implementations - use the grammar as the parsing layer underneath an LSP server for C++ tooling
Under The Hood
Architecture - The grammar is authored in grammar.js as a JavaScript DSL that imports and extends the base tree-sitter-c grammar, layering on C++-specific rules (classes, templates, operator overloading, lambdas). The tree-sitter CLI compiles this declarative grammar into a generated src/parser.c (a large, table-driven LR parser) plus a small hand-written src/scanner.c for lexical edge cases that can’t be expressed in pure grammar rules, with src/node-types.json describing the resulting AST node schema.
Tech Stack - The grammar source is JavaScript, but the shipped artifact is generated C code with zero runtime dependencies beyond tree-sitter-language; the repo ships first-class bindings for Rust (Cargo.toml, bindings/rust), Go (go.mod), Node.js (package.json, binding.gyp), Python (pyproject.toml, setup.py), and Swift (Package.swift), making it a genuinely multi-language distribution rather than a single-ecosystem library.
Code Quality - Correctness is validated through a test/corpus directory of annotated C++ snippets paired with expected parse trees, plus a separate test/highlight suite exercising the highlight queries; CI runs across the various language bindings before each Cargo/npm/PyPI release, and the grammar closely tracks tree-sitter-c to avoid duplicating shared C syntax rules.
API Design - Consumers interact with the crate through a minimal surface: a single exported LANGUAGE constant (or equivalent per binding) that’s handed to the generic tree-sitter runtime API, so there’s effectively no C++-specific API to learn beyond tree-sitter’s own parser/query interface, keeping integration overhead very low once tree-sitter itself is understood.
Used by 5 apps in this directory
Claude Context
AI Code Assistants
An MCP server and VS Code extension by Zilliz that turns your entire codebase into semantically searchable context for Claude Code, Cursor, and Gemini CLI, using vector embeddings and Merkle-tree change detection.
claude-mem
AI Agents · AI Development
Give your AI coding agents persistent memory — claude-mem captures everything that happens during sessions, compresses it with AI, and surfaces the right context in every future session automatically.
cocoindex
Data Engineering · AI Development
An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.
codegraph
Developer Tools · AI Code Assistants
A pre-indexed code knowledge graph that cuts AI tool calls by 58% and token costs by 16% — auto-syncing, 100% local, works with Claude Code, Cursor, Codex, and more.
GitNexus
Developer Tools · AI Code Assistants
Index any codebase into an interactive knowledge graph and give your AI agents deep architectural context via MCP — with zero servers required.