std/yaml
On this page
Index
- const
TAGGED - const
DOUBLE_QUOTED - const
SINGLE_QUOTED - const
LITERAL - const
FOLDED - const
FLOW - type
YamlErr- method
YamlErr.display
- method
- type
NodeKind - type
Node - type
RawNode - type
Doc - type
Ev - type
Enc - type
Dec - fn
decode - fn
encode_value - fn
decode_all - fn
encode_all - fn
parse - fn
parse_all - fn
to_json - fn
encode_node - fn
parse_doc - fn
root - fn
is_null - fn
to_str - fn
to_int - fn
to_float - fn
to_bool - fn
items - fn
pairs - fn
bad_key - fn
errors - fn
zero_node - fn
put_node - fn
to_node_field - fn
enc_new - fn
set_flow - fn
map_start - fn
map_end - fn
seq_start - fn
seq_end - fn
put_null - fn
put_bool - fn
put_int - fn
put_float - fn
put_str - fn
sorted_keys - fn
finish - fn
dec_new - fn
unknown_field - fn
tick - fn
leave - fn
parse_docs - fn
finish_all - fn
to_duration - fn
to_time - fn
put_time - fn
to_civil - fn
zero_civil - fn
put_civil - fn
to_bytes - fn
put_duration - fn
put_bytes
Constants
TAGGED
const TAGGED: Int = 1Style bits of a Node, as yaml.v3’s Style: TAGGED (the tag is written),
DOUBLE_QUOTED, SINGLE_QUOTED, LITERAL, FOLDED, FLOW.
DOUBLE_QUOTED
const DOUBLE_QUOTED: Int = 2SINGLE_QUOTED
const SINGLE_QUOTED: Int = 4LITERAL
const LITERAL: Int = 8FOLDED
const FOLDED: Int = 16FLOW
const FLOW: Int = 32Types
YamlErr
struct YamlErr {
line: Int
msg: Str
}Displays as yaml: line 3: mapping values are not allowed in this context;
type mismatches as yaml: unmarshal errors:\n line 2: cannot unmarshal !!str x into int, all of them together.
YamlErr.display
fn (e: YamlErr) display() -> StrNodeKind
enum NodeKind { Document, Sequence, Mapping, Scalar, Alias }The kinds of node yaml.v3’s Node has.
Node
struct Node {
kind: NodeKind
style: Int
tag: Str
value: Str
anchor: Str
head_comment: Str
line_comment: Str
foot_comment: Str
alias: Node?
content: List[Node]
line: Int
column: Int
}A node of a YAML document, as yaml.v3’s Node: a Document holds its one root in
content, a Sequence its items, a Mapping its keys and values alternately, a
Scalar its text in value with its resolved tag (!!str, !!int, …), and an
Alias the anchor name in value and the node it names in alias. anchor is the
name an anchored node defines; head_comment, line_comment and foot_comment hold
the comments around the node as yaml.v3 associates them (# prefixes kept, lines joined by
a line feed); line and column count from 1.
RawNode
struct RawNode {
kind: Int
style: Int
tag: Str
value: Str
anchor: Str
alias: Int
content: List[Int]
line: Int
column: Int
head_comment: Str
line_comment: Str
foot_comment: Str
}A node of the document tree; children and aliases are indexes into Doc.nodes.
Doc
struct Doc {
nodes: List[RawNode]
anchors: Map[Str, Int]
root: Int
}Ev
struct Ev {
kind: Int
text: Str
style: Int
node: List[Node]
}A node event written by derive Yaml’s encoder: 1 mapping start, 2 mapping end, 3 sequence start, 4 sequence end, 5 a scalar (its text and style).
Enc
struct Enc {
evs: List[Ev]
flow: Bool
}The events of one document being written.
Dec
struct Dec {
errs: List[YamlErr]
dc: Int
ac: Int
ad: Int
active: List[Int]
strict: Bool
}The state of one decode: the type errors so far (yaml.v3 reports them together), and the counts of its limit on alias expansion.
Functions
decode
fn decode[T: Yaml](text: Str, strict: Bool = false) -> T ! YamlErrThe first document of text decoded into a struct that derives Yaml: a
mapping’s keys by the field names (or as wire names), the rest ignored, or
with strict an error (yaml.v3’s KnownFields).
The call is compiled as a call of the function derive Yaml generates
for T.
encode_value
fn encode_value[T: Yaml](v: T, indent: Int = 4) -> Str ! YamlErrv as one YAML document, written as yaml.v3’s Marshal does (indent 4 by
default, indent spaces from 2 to 9 as its SetIndent, keys in
field order, strings quoted when they would read back as another type, a map’s
keys sorted as yaml.v3 sorts them). The call is compiled as a call of the
function derive Yaml generates for T.
decode_all
fn decode_all[T: Yaml](text: Str, strict: Bool = false) -> List[T] ! YamlErrEvery document of text decoded into T (yaml.v3’s Decoder.Decode until the end);
the call is compiled as a call of the function derive Yaml generates for T.
encode_all
fn encode_all[T: Yaml](docs: List[T], indent: Int = 4) -> Str ! YamlErrThe documents written one after the other, each after the first behind a ---
line (yaml.v3’s Encoder.Encode called for each).
parse
fn parse(text: Str) -> Node ! YamlErrThe first document of text as a Node tree (a Document node; an empty text is a Document with no content).
parse_all
fn parse_all(text: Str) -> List[Node] ! YamlErrEvery document of text.
to_json
fn to_json(text: Str) -> Str ! YamlErrThe first document of text as JSON text (like toml.to_json): keys sorted, aliases
and merge keys resolved, a timestamp as its text, an empty document null; a
NaN or an infinity is an error, as for Go’s json.Marshal of yaml.v3’s value.
encode_node
fn encode_node(n: Node, indent: Int = 4) -> Str ! YamlErrn written as YAML (yaml.v3’s Marshal of a Node): a Document node as is, any other node as a document of its own; a tag is left out when the text resolves to it.
parse_doc
fn parse_doc(text: Str) -> Doc ! YamlErrThe first document of text as a node tree.
root
fn root(d: Doc) -> IntThe index of the document’s content node, -1 for an empty document.
is_null
fn is_null(d: Doc, i: Int) -> Boolto_str
fn to_str(d: Doc, i: Int, var st: Dec) -> (Bool, Str) ! YamlErrThe reads below return whether a value was read (a null, a mismatch, or a node of the wrong kind leaves the field alone, as yaml.v3 does) and the value; a mismatch is put in st.errs (yaml.v3 reports every one together), and only an explicit tag that its text does not fit ends the decode.
to_int
fn to_int(d: Doc, i: Int, var st: Dec) -> (Bool, Int) ! YamlErrto_float
fn to_float(d: Doc, i: Int, var st: Dec) -> (Bool, Float) ! YamlErrto_bool
fn to_bool(d: Doc, i: Int, var st: Dec) -> (Bool, Bool) ! YamlErritems
fn items(d: Doc, i: Int, what: Str, var st: Dec) -> (Bool, List[Int])The items of a sequence node (what names the target type in the error).
pairs
fn pairs(d: Doc, i: Int, what: Str, var st: Dec) -> (Bool, List[(Str, Int, Int)]) ! YamlErrThe key and value node of each entry of a mapping node, as yaml.v3 decodes them as (key, value node, key line) (its own entries, then its merge key’s; a repeated key or a key that is not a scalar is put in st.errs; a bad merge value ends the decode).
bad_key
fn bad_key(d: Doc, v: Int, var st: Dec) -> Bool ! YamlErrPuts in errs the error of a pairs entry for a key that is not a scalar (its value v is negative) or ends the decode for a bad merge value; the generated reader calls it for such an entry.
errors
fn errors(st: Dec) -> YamlErrThe error of a decode that collected st.errs (not empty): yaml.v3’s “unmarshal errors:” list.
zero_node
fn zero_node() -> NodeThe value of a Node field the document does not hold: a null scalar (yaml.v3 has a Node of kind 0, which it writes as null).
put_node
fn put_node(var w: Enc, n: Node)Writes a Node field as it is (yaml.v3 writes a Node value through its encoder.node).
to_node_field
fn to_node_field(d: Doc, i: Int, var st: Dec) -> (Bool, Node) ! YamlErrA Node field: the node itself, an alias left an alias (yaml.v3 stops at the Node type before its alias handling).
enc_new
fn enc_new() -> Encset_flow
fn set_flow(var w: Enc, flow: Bool)Makes the next mapping or sequence started a flow one (yaml.v3’s e.flow).
map_start
fn map_start(var w: Enc)map_end
fn map_end(var w: Enc)seq_start
fn seq_start(var w: Enc)seq_end
fn seq_end(var w: Enc)put_null
fn put_null(var w: Enc)put_bool
fn put_bool(var w: Enc, b: Bool)put_int
fn put_int(var w: Enc, n: Int)put_float
fn put_float(var w: Enc, f: Float)put_str
fn put_str(var w: Enc, s: Str)A string as yaml.v3 writes it: quoted when it would read back as another type, a literal block when it has a line break (flow: quoted instead).
sorted_keys
fn sorted_keys(keys: List[Str]) -> List[Str]The keys of a map[string] in yaml.v3’s order (letters by code point, digit runs by value).
finish
fn finish(w: Enc, indent: Int) -> Str ! YamlErrThe document the events make, indented by indent spaces (yaml.v3’s SetIndent;
its Marshal uses 4; the emitter takes 2 to 9).
dec_new
fn dec_new(strict: Bool) -> Decstrict: an unknown key is an error (yaml.v3’s KnownFields).
unknown_field
fn unknown_field(var st: Dec, k: Str, line: Int, typ: Str)Puts the unknown key k, on line, of a struct typ in st.errs when the decode is strict.
tick
fn tick(d: Doc, i: Int, var st: Dec) -> Bool ! YamlErrCounts the read of node i (for an alias, also of its target, and enters it:
leave undoes that); fails on yaml.v3’s document contains excessive aliasing
or an anchor that contains itself. The generated readers call it first.
leave
fn leave(var st: Dec, entered: Bool)parse_docs
fn parse_docs(text: Str) -> List[Doc] ! YamlErrEvery document of text (parse reads the first).
finish_all
fn finish_all(ws: List[Enc], indent: Int) -> Str ! YamlErrThe documents the event lists make, one after another.
to_duration
fn to_duration(d: Doc, i: Int, var st: Dec) -> (Bool, Duration) ! YamlErrA Duration field (yaml.v3’s time.Duration): a string in Duration.parse syntax;
an int or a float is an error there as here.
to_time
fn to_time(d: Doc, i: Int, var st: Dec) -> (Bool, Time) ! YamlErrA Time field: a timestamp scalar (yaml.v3’s 2001-12-14, 2001-12-14 21:59:43.10, 2001-12-14t21:59:43.10-05:00)
as its instant, or any other text in RFC 3339; the zone is not kept.
put_time
fn put_time(var w: Enc, t: Time)Writes a Time as RFC 3339 in UTC.
to_civil
fn to_civil(d: Doc, i: Int, var st: Dec) -> (Bool, time.Civil) ! YamlErrA time.Civil field: a Time field that keeps the offset of the timestamp (yaml.v3’s time.Time does).
zero_civil
fn zero_civil() -> time.CivilThe value of a time.Civil field the document does not hold: 1970-01-01T00:00:00Z.
put_civil
fn put_civil(var w: Enc, c: time.Civil)Writes a Civil as RFC 3339 with its offset.
to_bytes
fn to_bytes(d: Doc, i: Int, var st: Dec) -> (Bool, Bytes) ! YamlErrA Bytes field, as yaml.v3’s []byte: a sequence of ints 0 to 255.
put_duration
fn put_duration(var w: Enc, d: Duration)Writes a Duration as Go’s Duration.String text (1h30m0s).
put_bytes
fn put_bytes(var w: Enc, b: Bytes)Writes Bytes as a sequence of ints, as yaml.v3 writes a []byte.
↑ index