tree-sitter-toml
A tree-sitter grammar for TOML configuration files
Repository Health
Technical Analysis
tree-sitter-toml (published to crates.io as tree-sitter-toml-ng) is a tree-sitter grammar for the TOML configuration language, maintained under the tree-sitter-grammars organization. It parses TOML source into a concrete syntax tree that updates incrementally as text changes, providing fast, error-tolerant parsing for editors and tooling.
The grammar ships bindings for Rust, Node, and other ecosystems along with editor query files, making it straightforward to add TOML syntax highlighting and structural analysis to tree-sitter-based tools.
What You Get
- A complete tree-sitter grammar for TOML with a generated C parser
- Language bindings including the tree-sitter-toml-ng Rust crate and an npm package
- Highlight and query files for editor integration
- Incremental, error-tolerant parsing suited to live editing
Common Use Cases
- Syntax highlighting for TOML in tree-sitter-based editors
- Structural navigation and folding of TOML tables and keys
- Linting, formatting, and static analysis of TOML config
- Language-server and code-intelligence backends for TOML
Under The Hood
Architecture - The grammar is defined in grammar.js using tree-sitter’s DSL and compiled to a C parser with an external scanner for TOML’s string and datetime tokens. Bindings expose a language() entry point that consumers register with a tree-sitter runtime.
Tech Stack - The grammar definition is JavaScript; the generated parser is C. A Rust crate is published as tree-sitter-toml-ng, and an npm package is available for Node, built via the standard tree-sitter binding toolchain.
Code Quality - The repository is maintained under the tree-sitter-grammars organization and follows its conventions, with a parser test corpus and query files. As a -ng (next-generation) grammar, it supersedes older TOML grammars in the ecosystem.
API Design - Usage is a single call: import the binding and pass its language object to a tree-sitter parser. Shipped queries reduce editor glue, and the crate follows tree-sitter-grammars naming conventions.