Skip to main content

helm_schema_syntax/
lib.rs

1//! Templated-YAML frontend: one parser for the Helm "YAML with holes"
2//! document language.
3//!
4//! A Helm template is two interleaved languages: Go template actions with a
5//! real grammar (parsed by tree-sitter), and YAML layout recovered from the
6//! text between actions. This crate owns the second half. It tokenizes a
7//! template source into lines and action spans, then runs a layout parser
8//! over the indent structure, producing a [`TemplatedDocument`] CST in which
9//! YAML structure (mapping entries, sequence items, scalars, block scalars),
10//! template control regions (`if`/`with`/`range`/`define`/`block` with their
11//! branches), output holes, and comments are all first-class nodes carrying
12//! byte spans.
13//!
14//! # Dependency direction
15//!
16//! `helm-schema-syntax` depends only on the tree-sitter grammar crate and is
17//! the single owner of the raw Go-template *tree* parse
18//! ([`parse_go_template`]). `helm-schema-ast` layers the typed expression AST
19//! (`TemplateExpr`) on top and re-exports this crate's YAML lexical helpers;
20//! it depends on this crate, never the reverse. Expression-level facts
21//! (`toYaml`-ness, `nindent` widths) intentionally stay out of the CST: the
22//! layout is decided by document shape alone, and expression semantics are
23//! applied by consumers that already own the expression parser.
24//!
25//! # Layout semantics and the line-model contract
26//!
27//! Control actions in real charts frequently do not nest cleanly with YAML
28//! structure (a mapping entry opened inside an `if` branch can adopt children
29//! after `{{ end }}`). Container structure is therefore derived purely from
30//! the visible YAML lines by indent discipline — action-only lines, comments,
31//! and blanks are transparent to layout — and control regions are attached
32//! into the tree as first-class overlay nodes. Regions whose branch bodies
33//! align with whole nodes stay structured; regions that provably violate the
34//! well-nested assumption are flagged (or degraded to [`Node::Opaque`] when
35//! they open mid-scalar) instead of guessed at.
36//!
37//! open-slot semantics that `helm-schema-ast`'s attribution previously
38//! recovered with an O(n²) per-query line replay; here the parse is a single
39//! pass and each query is an O(depth) chain walk.
40
41mod actions;
42mod cst;
43mod dump;
44mod lines;
45mod parse;
46mod yaml_scan;
47
48pub use actions::parse_go_template;
49pub use cst::{
50    BlockScalar, CommentLine, ControlBranch, ControlKind, ControlRegion, MappingEntry, Node,
51    OpaqueKind, OpaqueNode, OutputAction, ScalarLine, ScalarPart, ScalarParts, SequenceItem, Span,
52    TemplatedDocument,
53};
54pub use yaml_scan::{parse_yaml_key, structural_mapping_colon, unquote_yaml_scalar};