tree-sitter-cmake

An incremental Tree-sitter grammar that parses CMake source into a concrete syntax tree.

Library
Cargo
v0.7.4
59stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity52
Maintenance24
Community44
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture72
Code Quality68
Innovation70
Learning Curve78

tree-sitter-cmake is a Tree-sitter grammar for the CMake build language. It turns CMake source files into a fast, incrementally-updated concrete syntax tree that editors, language tooling, and static analyzers can walk to power syntax highlighting, structural navigation, and code intelligence.

Originally built to give nvim-treesitter a CMake parser, it ships bindings for Rust, C, Node, Python, Go, Swift, and Zig from a single grammar definition. The Rust crate exposes the compiled parser as a tree_sitter_language::LanguageFn so it plugs directly into any Tree-sitter host.

What You Get

  • A complete Tree-sitter grammar for the CMake build language, compiled to a portable C parser.
  • A Rust binding exposing the parser as a tree_sitter_language::LanguageFn for the Tree-sitter runtime.
  • Highlight, injection, and other query files ready for editor integration.
  • Multi-language bindings (C, Node, Python, Go, Swift, Zig) generated from the same grammar.

Common Use Cases

  • Syntax highlighting for CMakeLists.txt and .cmake files in editors like Neovim.
  • Structural code navigation, folding, and text objects over CMake source.
  • Static analysis and linting tools that need a reliable CMake parse tree.

Under The Hood

Architecture - The grammar is authored in grammar.js using Tree-sitter’s DSL and compiled to a portable src/parser.c plus src/node-types.json; language bindings under bindings/ (rust, c, node, python, go, swift, zig) each wrap that generated parser, and queries/ holds the highlight and injection query files editors consume.

Tech Stack - The Rust binding (bindings/rust/lib.rs, built via build.rs with the cc crate) depends only on tree-sitter-language at runtime and tree-sitter for dev/testing; the project also carries package manifests for npm, PyPI, Go, Swift Package Manager, and Zig so one grammar serves every ecosystem.

Code Quality - Correctness is anchored by a Tree-sitter test corpus under test/, exercised through the standard tree-sitter test harness; the generated parser is deterministic output of the grammar, so review effort centers on grammar.js and the query files rather than the emitted C.

API Design - The public surface is intentionally minimal: the crate exports a single LANGUAGE constant (LanguageFn) plus the query strings, matching the conventions of every other Tree-sitter grammar, so anyone familiar with the ecosystem can wire it into a parser in a few lines.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search