Skip to main content

Module yaml_ast

Module yaml_ast 

Source
Expand description

Typed AST wrappers over the in-tree YAML CST.

These wrappers give value-extraction consumers (metadata, bibliography, includes, hashpipe) a typed traversal API over the rowan CST produced by crate::parser::yaml::parse_yaml_tree, replacing the external yaml_parser crate’s ast module. They follow the house pattern (super::headings, super::references): newtype wrappers with hand-written AstNode impls and rowan::ast::support-based accessors.

Two CST facts shape the API:

  • YAML parses produce one or more YAML_DOCUMENT children under a stream-equivalent container. Standalone parses (crate::parser::yaml::parse_yaml_tree) root the tree at YAML_STREAM; embedded parses nest the documents directly under the host wrapper (YAML_METADATA_CONTENT for frontmatter, HASHPIPE_YAML_CONTENT for hashpipe), which plays the stream role for its singleton-stream embedding. parse_yaml_document centralizes the descent so no consumer re-implements it.
  • YAML_BLOCK_MAP_KEY includes the trailing : (YAML_COLON) token, so YamlBlockMapKey::scalar reads the YAML_SCALAR node child rather than the whole-key text.

Scalar style is not a CST kind — every style is a YAML_SCALAR node (wrapping YAML_SCALAR_TEXT content) — so YamlScalar detects the style from the leading byte and cooks via the shared [crate::parser::yaml::cook] primitives.

Structs§

YamlBlockMap
A block mapping (key: value entries).
YamlBlockMapEntry
One key: value pair in a block mapping.
YamlBlockMapKey
The key side of a block-map entry. Holds the YAML_SCALAR node AND the trailing YAML_COLON token.
YamlBlockMapValue
The value side of a block-map entry: a scalar, a nested container, or empty.
YamlBlockSequence
A block sequence (- item entries).
YamlBlockSequenceItem
One - item in a block sequence. The leading - is a YAML_BLOCK_SEQ_ENTRY token, skipped by the content projections.
YamlDocument
A single YAML document inside the stream.
YamlFlowMap
A flow mapping ({k: v, ...}).
YamlFlowMapEntry
One k: v pair in a flow mapping.
YamlFlowMapKey
The key side of a flow-map entry.
YamlFlowMapValue
The value side of a flow-map entry.
YamlFlowSequence
A flow sequence ([a, b, c]).
YamlFlowSequenceItem
One item in a flow sequence.
YamlScalar
A scalar value node. Its leaves are the per-physical-line content fragments (YAML_SCALAR_TEXT) interleaved with NEWLINE (and, for embedded hashpipe, line-prefix) tokens; raw reassembles them.

Enums§

YamlNode
The five concrete node shapes a value, sequence item, or document body can take. None (i.e. an absent YamlNode) models an empty YAML value.
YamlScalarStyle
The lexical style of a scalar, detected from its raw source. (The CST does not record style as a distinct kind — every style is a YAML_SCALAR node.)

Functions§

parse_yaml_document
Parse input and return the first YAML document. Descends through any stream-equivalent container ([is_stream_equivalent]) so it works against standalone parses (rooted at YAML_STREAM) and host embeddings alike. Returns None when the input fails the structural validator (no tree) or has no document.
parse_yaml_documents
Parse input and return every YAML document in the stream. Most consumers only need the first (parse_yaml_document); this exists for multi-document completeness (a: 1\n---\nb: 2).