moonyaml
YAML 1.2.2's core schema, the writer, the document model, and the typed codec.
Types
pub(all) suberror Malformed {
Read(Refused)
Shape(@json.JsonDecodeError)
} derive(@debug.Debug)
Why a document did not become the value the caller asked for.
Two things can go wrong, and they are different things: the YAML may not have been read at all, or it may have been read and not be the shape a type needs. Both carry where — the reader's position, or the path into the document — so a caller can say which line to look at.
Read(Refused)
The text is not YAML at all: see Refused for the rule it broke.
Shape(@json.JsonDecodeError)
The document read fine and is not the shape the type asked for. The path is a JSON Pointer into what was read, /servers/2/port.
pub fn Malformed::output(Self, &Logger) -> Unit
The value <code>Show</code> prints, written to the logger it is given.
pub fn Malformed::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub fn Malformed::to_string(Self) -> String
The value as <code>Show</code> writes it, for a person to read.
pub impl Show for Malformed
An implementation of a trait, as the compiler generated it.
pub(all) suberror Refused {
Unexpected(At, Char)
Truncated(At)
BadEscape(At)
BadIndent(At)
BadTag(At, String)
BadAnchor(At, String)
Repeated(At, String)
Trailing(At)
TooDeep(At)
Exceeded(at~ : At, limit~ : Int32, got~ : Int32)
BadUtf8(At)
Disallowed(At, String)
} derive(Eq, @debug.Debug)
Why a document was refused.
YAML's own answer to ambiguity is to be permissive, which is how a configuration file comes to mean something other than what it looks like. This reader refuses instead: anything it cannot resolve to one reading is an error with a position, never a guess.
Unexpected(At, Char)
A character that cannot stand where it was written.
Truncated(At)
The text ends inside a document: a quote, a bracket or a block scalar that was never closed.
BadEscape(At)
A double-quoted escape that is not one of §5.7's.
BadIndent(At)
A line indented to a column that lines up with nothing.
BadTag(At, String)
A tag nobody has, or a node tagged as something it cannot be.
BadAnchor(At, String)
An alias naming an anchor that was not written before it.
Repeated(At, String)
A key written twice, under duplicates: Reject.
Trailing(At)
A second document where one was asked for.
TooDeep(At)
Nesting past Flavor::depth.
Exceeded(at~ : At, limit~ : Int32, got~ : Int32)
Aliases expanding past Flavor::budget, with the limit and what it reached.
BadUtf8(At)
Not UTF-8, from the byte entry points.
Disallowed(At, String)
A construct this version does not have: a flow collection under the strict dialect, a tag or an anchor under a schema that has none, a key that is a collection where the value tree has only string keys.
pub fn Refused::at(Self) -> At
Where the refusal happened.
Every variant carries a position, so a caller that wants to report the line and column does not have to match all twelve of them to get at it.
pub fn Refused::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Refused::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Refused::output(Self, &Logger) -> Unit
The value <code>Show</code> prints, written to the logger it is given.
pub fn Refused::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub fn Refused::to_string(Self) -> String
The value as <code>Show</code> writes it, for a person to read.
pub impl Show for Refused
An implementation of a trait, as the compiler generated it.
pub(all) struct At {
at : Int32
line : Int32
column : Int32
} derive(Eq, @debug.Debug)
Where in the source something is: the offset in code units, and the line and column a person counts from one.
Every refusal carries one, because a configuration file that will not load is read by a person who needs to know which line to look at.
at : Int32
The offset in code units from the start of the text.
line : Int32
The line, counting from one.
column : Int32
The column, counting from one.
pub fn At::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn At::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn At::output(Self, &Logger) -> Unit
The value <code>Show</code> prints, written to the logger it is given.
pub fn At::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub fn At::to_string(Self) -> String
The value as <code>Show</code> writes it, for a person to read.
pub impl Show for At
An implementation of a trait, as the compiler generated it.
pub(all) enum Duplicates {
Last
First
Reject
} derive(Eq, @debug.Debug)
What to do when a mapping names the same key twice.
YAML 1.2.2 §3.2.1.1 says the keys of a mapping are unique and leaves the handling of a duplicate to the processor. Every loader in reach takes the last one, which is what Last does; First and Reject are here because a configuration file with a key written twice is usually a mistake someone would rather be told about.
Last
The last value written for a key is the one the mapping has.
First
The first value written for a key is the one the mapping has.
Reject
A repeated key is refused, with the position of the second one.
pub fn Duplicates::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Duplicates::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Duplicates::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub(all) struct Flavor {
depth : Int32
duplicates : Duplicates
aliases : Bool
budget : Int32
} derive(Eq, @debug.Debug)
How a document is read: the limits, and what to do with a duplicate key.
The preset is strict. Build another with Flavor::new, or update one in place with { ..strict, depth: 64 }.
depth : Int32
How deep a document may nest. See depth.
duplicates : Duplicates
What a key written twice means. See Duplicates.
aliases : Bool
Whether an alias may be resolved at all: false refuses one outright, which is what a caller reading untrusted input may want.
budget : Int32
How many nodes the aliases of one document may expand to. See budget.
pub fn Flavor::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Flavor::new(depth? : Int32, duplicates? : Duplicates, aliases? : Bool, budget? : Int32) -> Self
A flavor by name, every knob with the preset's value.
pub fn Flavor::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Flavor::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub(all) enum Kind {
Null
Bool(Bool)
Number(Double)
Str(String)
Sequence(Array[Node])
Mapping(Array[(Node, Node)])
Alias(String)
}
What a node is.
An alias is a node of its own rather than a copy of what it names: a document with an anchor and three aliases is three references, and writing it back as twelve copies would be a different document.
Null
An empty node: ~, null, or nothing written at all.
Bool(Bool)
A boolean, which only true and false are under the core schema.
Number(Double)
A number, held as the double it denotes.
Str(String)
A string: everything that is not one of the above and was not tagged.
Sequence(Array[Node])
A sequence, in block or flow style.
Mapping(Array[(Node, Node)])
A mapping, as the pairs it was written with: order is part of it, and a repeated key is kept twice.
Alias(String)
A reference to a node written earlier, by the anchor it was given.
pub(all) enum Layout {
Block
Flow
Auto
} derive(Eq, @debug.Debug)
How a collection is laid out.
Block is the style a configuration file is written in: one entry per line, a person can read it and a diff shows one change per line. Flow is the brace and bracket form, which JSON shares and which a machine-generated file often wants. Auto picks per collection: flow when it holds nothing but scalars and the whole of it fits in Style::width, block otherwise. A collection of collections stays block, because that is the shape of a configuration file.
Block
One entry per line, indented.
Flow
{a: 1} and [1, 2], which is JSON's own shape.
Auto
Flow for a collection of scalars that fits in one line, block otherwise.
pub fn Layout::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Layout::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Layout::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub(all) struct Node {
kind : Kind
text : String
style : ScalarStyle
flow : Bool
anchor : String?
tag : String?
before : Array[String]
after : String?
explicit : Bool
closed : Bool
}
One node of a document.
kind : Kind
What the node is.
text : String
A scalar as it was written, before resolution: 014, yes, ~.
Keeping the spelling is what makes a round trip a round trip: 014 read as twelve and written as 12 would be the same value in a different document.
style : ScalarStyle
How a scalar was written. Meaningless for a collection.
flow : Bool
Whether a collection was written in flow style.
anchor : String?
The &name the node was given, if it was given one.
tag : String?
The tag written in front of the node, resolved through the document's %TAG handles — tag:yaml.org,2002:str rather than !!str.
before : Array[String]
The comment lines written above this node, without their #.
after : String?
The comment at the end of this node's last line, without its #.
explicit : Bool
Whether the document this node heads was opened by an explicit ---.
The markers are the frame of a document rather than its content (§9.1.1), but they are written as deliberately as anything else, and a document that had them gets them back. Both are false for every node that is not a document's root.
closed : Bool
Whether the document was closed by an explicit ....
pub fn Node::anchored(Self, String) -> Self
This node, anchored.
pub fn Node::commented(Self, before~ : Array[String], after~ : String) -> Self
This node, with the comments written around it.
pub fn Node::events(Self) -> String
One document as the events a parser produces for it: +DOC down to -DOC, with a +MAP/+SEQ for a collection, =VAL for a scalar and =ALI for a reference, each nested one space further in than the event that opened it.
The notation is the YAML Test Suite's, which is where it is specified: the style a scalar was written in is the character before its text (:, ', ", |, >), a flow collection carries {} or [], an anchor &name and a tag <tag> come before the value, and control characters are escaped.
This is the document as a parse rather than as a value: a key that is not a string, a key written twice, two documents in one stream — all of them have events, and none of them has a Json. A caller who wants to know whether two documents are the same *document* rather than the same value can compare these.
pub fn Node::in_flow(Self, Bool) -> Self
This node, written in flow style.
pub fn Node::map(Array[(Self, Self)]) -> Self
A block mapping.
pub fn Node::of_json(Json) -> Self
A tree for a Json value: the document a program would write for it.
pub fn Node::of_kind(Kind, String) -> Self
A scalar of a known kind, keeping the spelling it was read from.
pub fn Node::same(Self, Self) -> Bool
Whether two documents would be written the same way.
The comparison a round trip is: read, write, read again, and the second tree is the first one. Positions are not in the tree, so this is equality of content.
pub fn Node::scalar(String) -> Self
A plain scalar, which is how most of YAML is written.
pub fn Node::seq(Array[Self]) -> Self
A block sequence.
pub fn Node::styled(Self, ScalarStyle) -> Self
This node, written in a particular scalar style.
pub fn Node::tagged(Self, String) -> Self
This node, tagged.
pub fn Node::to_json(Self) -> Json
The Json this document denotes, with its aliases expanded.
pub(all) enum Quotes {
Minimal
Single
Double
} derive(Eq, @debug.Debug)
Which quote a string gets when it needs one.
Minimal quotes only what would otherwise read as something else, which is what makes the output look written rather than generated. Single and Double are for a caller whose output feeds a second reader that is happier with one form.
Minimal
Quote only a string that would otherwise read as something else.
Single
Every string that has to be quoted gets '.
Double
Every string that has to be quoted gets ", escapes and all.
pub fn Quotes::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Quotes::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Quotes::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub(all) struct Rules {
yes_no : Bool
letters : Bool
octal : Bool
binary : Bool
underscores : Bool
sexagesimal : Bool
strings : Bool
} derive(Eq, @debug.Debug)
What a YAML version resolves an unquoted scalar to.
The three released versions disagree with each other, and the disagreements are all here rather than in the scanner: 1.1 reads yes as a boolean, 014 as twelve and 1:30 as ninety, 1.2 reads all three as strings, and StrictYAML reads every scalar as a string whatever it looks like. A version is a set of rules over one reader, which is why this library has one parser and not four.
A dialect nobody has published yet — a configuration language of your own, a pre-1.0 variant — is a Rules of your own, passed through Schema. Nothing here is closed.
yes_no : Bool
yes/no/on/off are booleans (YAML 1.1 §10.3).
letters : Bool
y/n, in either case, are booleans — YAML 1.0 only; 1.1 dropped them.
octal : Bool
A 0 prefix means octal: 014 is twelve (1.1 §10.3); 1.2 spells it 0o14.
binary : Bool
0b1010 is ten (1.1 §10.3).
underscores : Bool
1_000 is a thousand (1.1 §10.3).
sexagesimal : Bool
1:30 is ninety and 1:30.5 is ninety and a half (1.1 §10.3).
strings : Bool
Every scalar is a string, whatever it looks like — StrictYAML's first rule, and the reason a StrictYAML document never surprises a reader.
pub fn Rules::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Rules::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Rules::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
pub(all) enum ScalarStyle {
Plain
Single
Double
Literal(Int32)
Folded(Int32)
} derive(Eq)
How a scalar was written.
A block scalar carries the chomping indicator that was written with it, because | and |- are different strings at the end of a line.
Plain
Nothing around it: one.
Single
'one', where a backslash is a backslash.
Double
"one", the only form with escapes.
Literal(Int32)
| with its chomping indicator: the breaks are content, one per line.
Folded(Int32)
> with its chomping indicator: the breaks fold, and a blank line spells one.
pub fn ScalarStyle::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn ScalarStyle::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub(all) struct Schema {
resolve : (String, Bool, String?, At, Rules) -> Json raise Refused
rules : Rules
merge : Bool
tags : Bool
anchors : Bool
flow : Bool
secondary : String
primary : String
}
What a YAML version does that the scanner cannot decide for it.
The scanner in this package is shared; what a version resolves a scalar to, and what it allows besides, is a Schema.
The one in this package is core, the core schema of §10.2. The v11, v10, strict and any packages beside it are each a schema over the same scanner, which is why a version is a resolver rather than a fork of the reader.
resolve : (String, Bool, String?, At, Rules) -> Json raise Refused
A scalar as the value it denotes: its text, whether it was quoted, the tag it carried if any, where it was, and the rules that decide.
rules : Rules
How this version resolves a scalar.
merge : Bool
Whether a << key merges its value into the mapping around it.
tags : Bool
Whether a node may carry a tag.
anchors : Bool
Whether a node may be named by an anchor and referred to by an alias.
flow : Bool
Whether a collection may be written in flow style.
secondary : String
The prefix a !! handle names when the document did not redefine it.
primary : String
The prefix a ! handle names when the document did not redefine it.
pub(all) struct Style {
indent : Int32
width : Int32
layout : Layout
quotes : Quotes
anchors : Bool
sort : Bool
} derive(Eq, @debug.Debug)
How a document is written: the indentation, the line width, the layout, the quotes, and whether a repeated subtree is written once and referred to after.
The preset is style. Build another with Style::new, or update one in place with { ..style, width: 120 }.
indent : Int32
Spaces per level.
width : Int32
The column past which a collection is no longer written on one line, and at which a long plain scalar is folded.
layout : Layout
How a collection is laid out. See Layout.
quotes : Quotes
Which quote a string gets when it needs one. See Quotes.
anchors : Bool
Whether a subtree written twice is written once with &a1 and referred to by *a1 after. Off for output that a person will edit by hand, because an anchor is a thing to read around; on by default for files a program writes, where it turns a repeated block into one line.
sort : Bool
Whether mapping keys are written in sorted order.
pub fn Style::equal(Self, Self) -> Bool
Whether two values are the same, as <code>Eq</code> defines it.
pub fn Style::new(indent? : Int32, width? : Int32, layout? : Layout, quotes? : Quotes, anchors? : Bool, sort? : Bool) -> Self
A style by name, every knob with the preset's value.
pub fn Style::not_equal(Self, Self) -> Bool
The negation of <code>equal</code>.
pub fn Style::to_repr(Self) -> @debug.Repr
The value as <code>Debug</code> writes it, for a test's output.
Values
pub let ancient_rules : Rules
YAML 1.0's, which is 1.1 plus the single letters y and n. The 1.1 revision removed them because a lone n is more often a name than a no.
pub let budget : Int32
How many nodes the aliases in one document may expand to.
An alias can name a node that itself contains aliases, so a dozen lines can expand to billions of nodes: the "billion laughs" shape, which is what YAML's alias facility costs unless something counts. There is no published value to follow, so this takes the safe side — enough for any document anyone meant to write, far short of exhausting memory. Flavor::new(budget=...) raises it, and aliases=false refuses an alias outright.
pub let core : Schema
The core schema of YAML 1.2.2 §10.2: what this package reads.
pub let core_rules : Rules
YAML 1.2's core schema: nothing but true/false, null, and the decimal, 0o and 0x numbers of §10.2.
pub let depth : Int32
How deep a document may nest.
500 is deep enough for any configuration file ever written and shallow enough that a reader which walks the tree cannot be driven off the stack by one that was not. A document that nests deeper than this is not a configuration file, and is refused rather than read.
pub let flow : Style
The same document, all in flow style — the form JSON shares.
pub let indent : Int32
How much a nested level is indented.
Two spaces: what almost every configuration file in the wild uses, and what a reader's eye is trained on.
pub let legacy_rules : Rules
YAML 1.1's type resolution, §10.3 of the 1.1 specification: the booleans, the octal and binary integers, the underscored numbers, and the base-60 form.
pub let strict : Flavor
The preset: refuse what is ambiguous, take the last of a repeated key, expand aliases within the budget.
pub let style : Style
The preset: two-space block style, folded at 80 columns, quoting only what has to be quoted, anchors for what repeats.
Block, not Auto: what this writes is a configuration file, and a configuration file is read one entry to a line. Auto is a knob for output whose reader is a machine.
pub let width : Int32
The column a writer folds at.
80: the width yamllint defaults to, which is itself the width of a terminal and of the Python PEP 8 convention the tooling around YAML grew up beside.
Functions
pub fn declared_version(StringView) -> (Int32, Int32)?
The version a stream declares in its first %YAML directive, if it declares one.
A reader may pick its rules from the document itself rather than from the caller, which is what any does. Only the first directive counts: §6.8.1 allows one per document, and the one that decides how the rest is read has to come before the rest.
pub fn dump(Json, style? : Style, rules? : Rules, indent? : Int32, sort? : Bool) -> Bytes
The same, as UTF-8 bytes — the s on dumps is the one Python puts on the form that answers a string.
pub fn dump_all(ArrayView[Json], style? : Style, rules? : Rules, indent? : Int32, sort? : Bool) -> Bytes
The same, as UTF-8 bytes.
pub fn dumps(Json, style? : Style, rules? : Rules, indent? : Int32, sort? : Bool) -> String
Write a Json tree as a YAML document.
Block style by default, which is what a configuration file is written in and what a person reads. A string is quoted only when plain would read back as something else — a number, a boolean, a null, or not at all — so the output looks like a file someone wrote rather than one a program emitted.
This is the reason to have a writer at all: a generator that builds YAML by joining strings gets the escaping wrong the first time a value contains a colon, and gets the indentation wrong the first time a value is a list.
style says how; indent and sort override the two knobs that change from call to call. A flat parameter wins over the record — see "Configuration" in the README.
pub fn dumps_all(ArrayView[Json], style? : Style, rules? : Rules, indent? : Int32, sort? : Bool) -> String
A stream of documents, each opened by its own ---.
The separator goes before each document rather than between them, which is the one convention that stays correct under concatenation: two streams joined end to end still read as their documents, and appending one is appending lines. A reader of either convention reads this one — a marker before the first document is not an error anywhere — so nothing is given up by choosing it.
pub fn[T : ToJson] dumps_of(T, style? : Style, indent? : Int32, sort? : Bool) -> String
A value of type T, written as a YAML document.
The other direction of loads_as, through the same ToJson trait, so a type that writes itself as JSON writes itself as YAML without knowing it.
pub fn[T : ToJson] dumps_of_all(ArrayView[T], style? : Style, indent? : Int32, sort? : Bool) -> String
A stream of values, each written as its own document.
pub fn emit(Node, indent? : Int32, from? : Int32) -> String
Emit a document as YAML, keeping the styles and comments it was read with.
indent is how far a nested block is indented, and from is how far the root already is — a document embedded in another one needs the second.
A document that was written under an explicit --- gets one back, on a line of its own; the comments above it stay above it.
pub fn events_all(Array[Node]) -> String
Every document's events, between the +STR and -STR that open and close a stream — one line per event, which is what makes two streams comparable line by line.
pub fn load(BytesView, flavor? : Flavor, schema? : Schema, bom? : Bool) -> Json raise Refused
The one document in src, decoded as UTF-8.
bom skips a leading byte-order mark, which YAML 1.2.2 §5.2 allows at the start of a stream and which an editor on Windows will happily write.
pub fn load_all(BytesView, flavor? : Flavor, schema? : Schema, bom? : Bool) -> Array[Json] raise Refused
Every document in src, decoded as UTF-8.
pub fn[T : @json.FromJson] load_as(BytesView, flavor? : Flavor, schema? : Schema, bom? : Bool) -> T raise Malformed
The one document in src, decoded as UTF-8, as a value of type T.
pub fn loads(StringView, flavor? : Flavor, schema? : Schema) -> Json raise Refused
The one document in src.
Raises Refused::Trailing if a second document follows, which is what tells a caller expecting one file's worth of configuration that it got a stream.
schema says which YAML version reads it; the default is core. A document that opens with %YAML 1.1 is not read as 1.2 by default — pick the version, or let the any package pick it for you.
pub fn loads_all(StringView, flavor? : Flavor, schema? : Schema) -> Array[Json] raise Refused
Every document in src, in order.
A stream with no documents at all is an empty array, not a null: nothing is not the same as one document containing nothing.
pub fn[T : @json.FromJson] loads_as(StringView, flavor? : Flavor, schema? : Schema) -> T raise Malformed
The one document in src, as a value of type T.
let config : Config = @moonyaml.loads_as(src)
T is anything that implements core's FromJson, which is the same trait a JSON document is read through: a type written for moonjson needs no second implementation to be read from YAML. That is the point of reading into the same Json tree — the shape of a value is one question, and which text it arrived in is another.
The default schema is 1.2's core. Read a 1.1 file with @moonyaml/v11's schema, or let @moonyaml/any pick it from the document.
pub fn parse(StringView, flavor? : Flavor, schema? : Schema) -> Node raise Refused
One document, as a tree.
pub fn parse_all(StringView, flavor? : Flavor, schema? : Schema) -> Array[Node] raise Refused
Every document in the stream, as trees.
A stream with nothing in it holds no document, which is what loads_all says too; parse is where a single document is owed, and it gives the null one.
pub fn[T : @json.FromJson + ToJson] round_trip(StringView, adjust? : (T) -> Unit, flavor? : Flavor, schema? : Schema) -> String raise Malformed
Read a document as T, let adjust change it, and write it back.
The three steps a configuration loader actually takes: read what the user wrote, fill in what they left out, write the whole of it back. adjust is where the defaults go, and it is also what says which type this is — a call with no adjust cannot tell.
moonyaml/yaml11
YAML 1.1: yes and no as booleans, 014 as octal, sexagesimals, 1_000, and the << merge key.
Values
pub let rules : @moonyaml.Rules
How YAML 1.1 resolves a scalar: yes/no/on/off are booleans, 014 is twelve, 0b1010 is ten, 1_000 is a thousand, and 1:30 is ninety.
pub let schema : @moonyaml.Schema
YAML 1.1's schema: the 1.1 types, and the merge key.
The merge key is 1.1's own (§7.1) — a << key whose value is a mapping, or a sequence of mappings, is folded into the mapping around it. It is not in 1.2, which is why this is a schema and not a default.
Functions
pub fn dumps(Json, style? : @moonyaml.Style, indent? : Int32, sort? : Bool) -> String
Write a value as YAML 1.1: a string that 1.1 would read back as a boolean or a number is quoted, so what is written is what is read.
pub fn dumps_all(ArrayView[Json], style? : @moonyaml.Style, indent? : Int32, sort? : Bool) -> String
Every document, each opened by its own ---.
pub fn load(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Json raise @moonyaml.Refused
The one document in src, decoded as UTF-8 and read as YAML 1.1.
pub fn load_all(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Array[Json] raise @moonyaml.Refused
Every document in src, decoded as UTF-8 and read as YAML 1.1.
pub fn loads(StringView, flavor? : @moonyaml.Flavor) -> Json raise @moonyaml.Refused
The one document in src, read as YAML 1.1.
pub fn loads_all(StringView, flavor? : @moonyaml.Flavor) -> Array[Json] raise @moonyaml.Refused
Every document in src, read as YAML 1.1.
moonyaml/yaml10
YAML 1.0's types, which 1.1 inherited but did not always keep: the single letters y and n are booleans here too.
Values
pub let rules : @moonyaml.Rules
How YAML 1.0 resolves a scalar: everything 1.1 does, and y/n — in either case — as booleans.
The 1.1 revision dropped the single letters, because a lone n is more often a name than a no: n: 1 in a table of columns is a heading, not a false. A file that says %YAML 1.0 means the older reading.
pub let schema : @moonyaml.Schema
YAML 1.0's schema.
Functions
pub fn dumps(Json, style? : @moonyaml.Style, indent? : Int32, sort? : Bool) -> String
Write a value as YAML 1.0.
pub fn dumps_all(ArrayView[Json], style? : @moonyaml.Style, indent? : Int32, sort? : Bool) -> String
Every document, each opened by its own ---.
pub fn load(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Json raise @moonyaml.Refused
The one document in src, decoded as UTF-8 and read as YAML 1.0.
pub fn load_all(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Array[Json] raise @moonyaml.Refused
Every document in src, decoded as UTF-8 and read as YAML 1.0.
pub fn loads(StringView, flavor? : @moonyaml.Flavor) -> Json raise @moonyaml.Refused
The one document in src, read as YAML 1.0.
pub fn loads_all(StringView, flavor? : @moonyaml.Flavor) -> Array[Json] raise @moonyaml.Refused
Every document in src, read as YAML 1.0.
moonyaml/strict
The strict dialect: block structure only, every scalar a string, no flow style, no anchors, no tags, no repeated keys.
Values
pub let flavor : @moonyaml.Flavor
The preset for reading StrictYAML: a repeated key is a fault.
StrictYAML rejects duplicate keys, and it is right to: a mapping that names the same key twice has no reading that a person could have predicted.
pub let rules : @moonyaml.Rules
How StrictYAML resolves a scalar: as text, always.
This is the whole of StrictYAML's first promise. port: 8080 and port: "8080" are the same string, enabled: yes is the word, and the caller says what a value means by reading it through a schema of its own. Nothing in a document is a number, a boolean or a null because of how it is spelled.
pub let schema : @moonyaml.Schema
StrictYAML's schema: text scalars, no tags, no anchors, no flow style.
Each of those is a feature StrictYAML removes, and each is removed for the same reason — it makes what a document says depend on something other than the text in front of the reader:
- a tag asks for a type the reader may not have;
- an anchor makes one node appear in two places, so the document is no longer a
tree you can read top to bottom;
- flow style packs structure onto a line, which is where the bracket-matching
mistakes come from.
Functions
pub fn dumps(Json, style? : @moonyaml.Style, indent? : Int32, sort? : Bool) -> String
Write a value as StrictYAML: every scalar is quoted unless it reads back as itself, because in StrictYAML there is nothing else it could be.
pub fn load(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Json raise @moonyaml.Refused
The one document in src, decoded as UTF-8 and read as StrictYAML.
pub fn loads(StringView, flavor? : @moonyaml.Flavor) -> Json raise @moonyaml.Refused
The one document in src, read as StrictYAML.
pub fn loads_all(StringView, flavor? : @moonyaml.Flavor) -> Array[Json] raise @moonyaml.Refused
Every document in src, read as StrictYAML.
StrictYAML has no multi-document streams — a file is a document — so this is the same as loads and exists to keep call sites that do not care about the difference working across versions.
moonyaml/any
The version a document asks for with %YAML, and 1.2.2 when it asks for nothing.
Functions
pub fn load(BytesView, flavor? : @moonyaml.Flavor, bom? : Bool) -> Json raise @moonyaml.Refused
The one document in src, decoded as UTF-8 and read with the rules it asks for.
pub fn loads(StringView, flavor? : @moonyaml.Flavor) -> Json raise @moonyaml.Refused
The one document in src, read with the rules it asks for.
pub fn loads_all(StringView, flavor? : @moonyaml.Flavor) -> Array[Json] raise @moonyaml.Refused
Every document in src, read with the rules the first of them asks for.
pub fn of(StringView) -> @moonyaml.Schema raise @moonyaml.Refused
The schema a stream asks for.
A document that opens with %YAML 1.1 says how it wants to be read, and 1.1's rules are not 1.2's: yes is a boolean there and a string here, 014 is twelve there and fourteen here. Reading it as 1.2 would silently give the caller a different value from the one the file's author wrote, which is the one failure mode a configuration loader must not have.
No directive means 1.2, which is the current release and what a file written without a version marker means today. A directive naming a major version this library does not have is refused, rather than read with the wrong rules.