This module implements a YAML 1.2 subset aimed at configuration files and
Markdown frontmatter. It supports a single document (optionally between
--- and ... markers), block mappings and sequences (including compact and
indentless sequences), single-line flow collections, comments, literal and
folded block scalars, single-line quoted scalars with all YAML escapes, and
plain scalars resolved with the YAML 1.2 core schema (null, booleans, decimal,
octal and hexadecimal integers, floats, .inf and .nan).
Mapping keys are their source text, so 1 and 01 are different keys.
Nesting is limited to 100 levels. Anchors, aliases, tags, directives,
complex keys, multi-line flow collections, multi-line quoted or plain
scalars, and multi-document streams are rejected with a parse error rather
than misread.
Tokenize source text for highlighting, including incomplete YAML snippets.
Slicing each token interval from source and concatenating them reproduces
the input exactly, including comments, whitespace, CRLF, and Unicode.
Anchors, aliases, tags, directives and document markers are recognized
lexically even when Yaml.parse_str rejects the document.
Map a token to a theme category without rendering or changing its text.
Mapping keys use PropertyName; scalar values use their core-schema
category. Quoted values and block-scalar scripts remain StringText.
Validate one complete document, reporting its source name and position.
Unlike Yaml.parse_str, this also rejects enabled lint checks. Legacy
boolean checks inspect unquoted values, never mapping keys or quoted text.
validate_as : DecodeValidationProps -> Try(a, [InvalidYaml(Error), ..errs]) where [a.Parseable([InvalidYaml(Error), ..errs])]
Validate then decode without rendering domain failures as compiler text.
A Parser that reads the rest of its input as one YAML document, for
composing YAML with other parsers.
It always consumes all input. ParseError carries the native YAML problem
and the shared location/path envelope; text runners provide original text coordinates.
The text of a Text value. Other values, including numbers and
booleans, are Err(WrongType); use Yaml.decode_str to read a plain
scalar such as 1.10 as text.
Render a parsed YAML value in Roc source-like notation for inspection.
The output is meant for debugging and test messages, not for writing
YAML. Control characters in text and keys are escaped, so the output is
always printable on one line.
Decode one YAML document straight into a Roc type, chosen by type
inference.
A mapping decodes into a record (by field name), or a Dict with Str or integer keys. Unknown keys are skipped; use Yaml.decode_str with unknown_keys: Reject to make them an error.
A sequence decodes into a List or, when it has exactly the right number of items, a tuple.
A scalar is resolved for the type that asks for it, using the YAML 1.2 core schema: Str takes any quoted or block scalar and any plain scalar except a null, so version: 1.10 stays "1.10"; Bool, the integer types, F32, F64 and Dec take the matching core-schema forms; a tag union without payloads takes the tag's name.
A null (null, ~ or an empty value) decodes as an empty list, dict or record, and fills a Try(_, [Null]) field with Err(Null).
A Try(_, [Missing]) field is Err(Missing) when its key is absent. Any other absent field fails with InvalidYaml, whose problem is MissingRequiredField(name) and whose path identifies that key.
Invalid YAML and values that do not fit the type both fail with
InvalidYaml, at the line and column of the offending value.
Stable lexical kinds; punctuation spelling is available in the source span.
Quotes include their delimiters. Block scalar content includes its original
indentation and line endings. Whitespace and comments are retained.
Complete means no lexical issue was detected; it does not establish YAML
semantic validity. Recovered preserves malformed source with diagnostics.
Limited preserves the input after reaching 256 open flow collections;
the remaining bytes become one Invalid token with a ResourceLimit issue.
The complete-error-row protocol supplied to custom parser_for implementations.
Its receiver hooks read builtin values while preserving native and domain failures.