Expand description
Templated-YAML frontend: one parser for the Helm “YAML with holes” document language.
A Helm template is two interleaved languages: Go template actions with a
real grammar (parsed by tree-sitter), and YAML layout recovered from the
text between actions. This crate owns the second half. It tokenizes a
template source into lines and action spans, then runs a layout parser
over the indent structure, producing a TemplatedDocument CST in which
YAML structure (mapping entries, sequence items, scalars, block scalars),
template control regions (if/with/range/define/block with their
branches), output holes, and comments are all first-class nodes carrying
byte spans.
§Dependency direction
helm-schema-syntax depends only on the tree-sitter grammar crate and is
the single owner of the raw Go-template tree parse
(parse_go_template). helm-schema-ast layers the typed expression AST
(TemplateExpr) on top and re-exports this crate’s YAML lexical helpers;
it depends on this crate, never the reverse. Expression-level facts
(toYaml-ness, nindent widths) intentionally stay out of the CST: the
layout is decided by document shape alone, and expression semantics are
applied by consumers that already own the expression parser.
§Layout semantics and the line-model contract
Control actions in real charts frequently do not nest cleanly with YAML
structure (a mapping entry opened inside an if branch can adopt children
after {{ end }}). Container structure is therefore derived purely from
the visible YAML lines by indent discipline — action-only lines, comments,
and blanks are transparent to layout — and control regions are attached
into the tree as first-class overlay nodes. Regions whose branch bodies
align with whole nodes stay structured; regions that provably violate the
well-nested assumption are flagged (or degraded to Node::Opaque when
they open mid-scalar) instead of guessed at.
open-slot semantics that helm-schema-ast’s attribution previously
recovered with an O(n²) per-query line replay; here the parse is a single
pass and each query is an O(depth) chain walk.
Structs§
- Block
Scalar - A literal block scalar (
|/>families): its header token and the suppressed body span, with any template actions inside the body kept as suppressed holes. - Comment
Line - A YAML
#comment line (which may itself contain template actions). - Control
Branch - One branch of a control region: its header action (
{{ if … }},{{ else }}, …) and the nodes emitted while the branch was active. - Control
Region - A template control region (
{{ if }}…{{ end }}and friends) with its branch bodies. Container structure is decided by the visible YAML lines alone, so a region’s branches hold exactly the nodes that opened and closed while the branch was active. - Mapping
Entry - One
key: …mapping entry line and, when the entry opens a scope, the nodes nested below it. - Opaque
Node - A span kept without further interpretation. Opaque nodes never guess: they preserve the raw span so downstream can attribute conservatively.
- Output
Action - A standalone-line output action (
{{ include "x" . }}on its own line). Inline actions inside scalars are represented asScalarPart::Holes instead. - Scalar
Line - A plain scalar content line that is not a mapping entry or sequence item:
flow-collection continuations,
---markers, malformed keys, and other text the layout keeps only for its popping effect. - Scalar
Parts - A scalar run split into literal text and template-action holes.
- Sequence
Item - One
- …sequence item line and the nodes nested below it. An inline- key: …entry appears as the first child with effective indentdash + 2. - Span
- A half-open byte range
[start, end)into the parsed source. - Templated
Document - A parsed templated-YAML source: the layout node forest with document boundaries.
Enums§
- Control
Kind - Go-template action that owns a structured body.
- Node
- A CST node. Containers own the nodes that structurally nest below them; control regions and action nodes are overlay nodes attached where they appear, without affecting container structure.
- Opaque
Kind - Classification of source retained without deeper CST structure.
- Scalar
Part - One literal or templated piece of a scalar run.
Functions§
- parse_
go_ template - Parse
sourcewith the tree-sitter Go-template grammar. This crate is the single owner of the raw Go-template tree parse;helm-schema-astre-exports this function and layers the typed expression AST on top. - parse_
yaml_ key - Parses a YAML mapping key from text ending immediately before its colon.
- structural_
mapping_ colon - The offset of the first colon that YAML treats as a mapping key/value
separator, or
Nonewhen the line has no such colon. - unquote_
yaml_ scalar - Strip one matching pair of surrounding single or double quotes from a YAML scalar, returning the inner text. Unquoted (or mismatched-quote) input is returned unchanged.