yamleam

yamleam — a pure-Gleam YAML 1.2 parser.

Parse YAML into a typed YamlNode tree with parse_raw, or decode it into your own types with parse and a standard gleam/dynamic/decode decoder, the same kind gleam_json takes. parse_documents and parse_documents_raw read multi-document streams. yamleam/exact parses into a tree that keeps every number’s text, for numbers that must stay exact.

Pattern-match the tree with the constructors in yamleam/node, and errors with those in yamleam/error. The README has the feature reference and the scalar resolution rules.

Types

pub type YamlError =
  error.YamlError
pub type YamlNode =
  node.YamlNode

Values

pub fn parse(
  source: String,
  decoder: decode.Decoder(a),
) -> Result(a, error.YamlError)

Parse a YAML source string and run a decoder on the resulting tree.

The decoder is a standard gleam/dynamic/decode.Decoder(a), the same type used by gleam_json.parse. Decoders written for JSON sources can be reused unchanged against YAML sources. Reads exactly one document; use parse_documents for multi-document streams.

pub fn parse_documents(
  source: String,
  decoder: decode.Decoder(a),
) -> Result(List(a), error.YamlError)

Parse a YAML stream containing one or more documents and run the given decoder against each document. Returns a list of decoded values in document order.

pub fn parse_documents_raw(
  source: String,
) -> Result(List(node.YamlNode), error.YamlError)

Parse a YAML stream containing one or more documents into a list of YamlNode trees. Documents are separated by --- (start) or ... (end) markers as defined in YAML 1.2 §9.

A stream with no markers and a single document returns [node]. An empty stream returns [].

Use parse_documents if you want each document run through a decoder.

pub fn parse_raw(
  source: String,
) -> Result(node.YamlNode, error.YamlError)

Parse a YAML source string into a typed YamlNode tree.

Returns a ParseError for invalid YAML, or an Unsupported error that names a feature outside the supported set. Reads exactly one document; use parse_documents_raw for multi-document streams.

Numbers resolve to YamlInt and YamlFloat. When a number must stay exactly as written, use yamleam/exact.parse, which keeps its text.

pub fn yaml_bool(b: Bool) -> node.YamlNode
pub fn yaml_float(f: Float) -> node.YamlNode
pub fn yaml_int(i: Int) -> node.YamlNode
pub fn yaml_list(items: List(node.YamlNode)) -> node.YamlNode
pub fn yaml_map(
  pairs: List(#(String, node.YamlNode)),
) -> node.YamlNode
pub const yaml_null: node.YamlNode
pub fn yaml_string(s: String) -> node.YamlNode
✨ Search Document