Skip to main content

Crate helm_schema_syntax

Crate helm_schema_syntax 

Source
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§

BlockScalar
A literal block scalar (| / > families): its header token and the suppressed body span, with any template actions inside the body kept as suppressed holes.
CommentLine
A YAML # comment line (which may itself contain template actions).
ControlBranch
One branch of a control region: its header action ({{ if … }}, {{ else }}, …) and the nodes emitted while the branch was active.
ControlRegion
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.
MappingEntry
One key: … mapping entry line and, when the entry opens a scope, the nodes nested below it.
OpaqueNode
A span kept without further interpretation. Opaque nodes never guess: they preserve the raw span so downstream can attribute conservatively.
OutputAction
A standalone-line output action ({{ include "x" . }} on its own line). Inline actions inside scalars are represented as ScalarPart::Holes instead.
ScalarLine
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.
ScalarParts
A scalar run split into literal text and template-action holes.
SequenceItem
One - … sequence item line and the nodes nested below it. An inline - key: … entry appears as the first child with effective indent dash + 2.
Span
A half-open byte range [start, end) into the parsed source.
TemplatedDocument
A parsed templated-YAML source: the layout node forest with document boundaries.

Enums§

ControlKind
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.
OpaqueKind
Classification of source retained without deeper CST structure.
ScalarPart
One literal or templated piece of a scalar run.

Functions§

parse_go_template
Parse source with the tree-sitter Go-template grammar. This crate is the single owner of the raw Go-template tree parse; helm-schema-ast re-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 None when 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.