tree-sitter-yaml
A tree-sitter grammar for YAML documents
Repository Health
Technical Analysis
tree-sitter-yaml is a tree-sitter grammar for the YAML data serialization language, maintained under the tree-sitter-grammars organization. It parses YAML source into a concrete syntax tree that updates incrementally as text changes, providing fast, error-tolerant parsing for editors and tooling.
The grammar handles YAML’s indentation-sensitive block structure, flow collections, anchors, and tags, and ships bindings for Rust, Node, and other ecosystems along with editor query files for highlighting and structural analysis.
What You Get
- A complete tree-sitter grammar for YAML with a generated C parser and external scanner
- Language bindings including a 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 YAML in tree-sitter-based editors
- Structural navigation and folding of YAML mappings and sequences
- Linting, formatting, and static analysis of YAML config
- Language-server and code-intelligence backends for YAML
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 that tracks YAML’s significant indentation, block scalars, and flow context. Bindings expose a language() entry point for consumers to register with a tree-sitter runtime.
Tech Stack - The generated parser and scanner are C (the repo’s primary language); the grammar definition is JavaScript. A Rust crate is published as tree-sitter-yaml, and an npm package is available for Node, built with the standard tree-sitter binding toolchain.
Code Quality - Maintained under the tree-sitter-grammars organization following its conventions, with a parser test corpus and query files. YAML’s whitespace sensitivity is handled by a hand-written external scanner, a nontrivial and carefully tested component.
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.