std/yaml/node
std/yaml/src/node.trb
The tree of a YAML document: every node with its tag, its anchor, its style, its comments and the position it starts
at. It is what Yaml().parse answers and what the writer writes back, so a tool can change one value of a
configuration file and keep everything else as it was written.
A scalar keeps its text: yes is the text "yes" until a schema or a target type says what it is.
type ScalarStyle
type ScalarStyle
How a scalar was written. Only a plain scalar is resolved by a schema; every other style is a text.
case Plain
case Plain
value, without quotes.
case SingleQuoted
case SingleQuoted
'value': no escapes, '' is one quote.
case DoubleQuoted
case DoubleQuoted
"value", with escapes.
case Literal
case Literal
|: a block whose line breaks are kept.
case Folded
case Folded
>: a block whose line breaks are folded into spaces.
type CollectionStyle
type CollectionStyle
How a sequence or a mapping was written: indented lines, or brackets and braces.
type YamlComments
type YamlComments
The comments that belong to a node. Each is the text after its #, as written.
type YamlContent
type YamlContent
What a node holds.
case Scalar
case Scalar(text: String, style: ScalarStyle)
A scalar: its text after quotes, escapes and folding are applied, and how it was written.
case Sequence
case Sequence(items: List<YamlNode>, style: CollectionStyle)
A sequence of nodes.
case Mapping
case Mapping(entries: List<YamlEntry>, style: CollectionStyle)
A mapping, with its entries in the order they were written.
case Alias
case Alias(name: String)
*name: the node the anchor &name stands on, once more.
type YamlEntry
type YamlEntry
One key: value of a mapping. A key is a node like any other and may be a collection.
type YamlNode
type YamlNode
One node of a YAML document, as it was written.
tag is the resolved tag: tag:yaml.org,2002:str for !!str, !Point for a local one, ! for the non-specific
tag of a quoted scalar written ! 'text', and None where the node has none. line and column are where the node
starts, counted from 1, and 0 for a node a program built.
Examples
use Yaml from "std/yaml"
const document = Yaml().parse("name: Ada\nlanguages: [en, de]\n")?
print document.root.at("name")?.text()
field content
content: YamlContent
Not documented.
field tag
tag: String? = None
Not documented.
field anchor
anchor: String? = None
Not documented.
field comments
comments: YamlComments = YamlComments()
Not documented.
field line
line: Int = 0
Not documented.
field column
column: Int = 0
Not documented.
fn scalar
static fn scalar(text: String, style: ScalarStyle = ScalarStyle.Plain): YamlNode
A scalar node, plain unless a style is given.
fn sequence
static fn sequence(items: List<YamlNode>, style: CollectionStyle = CollectionStyle.Block): YamlNode
A sequence node, in block style unless a style is given.
fn mapping
static fn mapping(entries: List<YamlEntry>, style: CollectionStyle = CollectionStyle.Block): YamlNode
A mapping node, in block style unless a style is given.
fn alias
static fn alias(name: String): YamlNode
*name.
fn empty
static fn empty(): YamlNode
The empty plain scalar, which every schema but the failsafe one reads as null.
fn text
fn text(): String?
The text of a scalar, or None for a collection and an alias.
fn items
fn items(): List<YamlNode>
The items of a sequence; empty for everything else.
fn entries
fn entries(): List<YamlEntry>
The entries of a mapping; empty for everything else.
fn isScalar
fn isScalar(): Bool
Whether the node is a scalar.
fn at
fn at(key: String): YamlNode?
The value of the first entry whose key is a scalar with the text key.
fn updated
fn updated(key: String, value: YamlNode): YamlNode
The node with the value of key replaced by value, or with a new entry at the end where there is none. The
entry keeps its key, its comments and its position among the others, and value keeps the comments of the value it
replaces where it has none of its own.
type YamlTagDirective
type YamlTagDirective
A %TAG directive: the handle !e! stands for the prefix tag:example.com,2000:.
type YamlDocument
type YamlDocument
One document of a YAML stream: its root node, its directives, whether it was opened with --- and closed with ...,
and the comments that stand before and after the root.
field root
root: YamlNode
Not documented.
field version
version: String? = None
"1.1" or "1.2" from a %YAML directive, and None for a document without one.
field tagDirectives
tagDirectives: List<YamlTagDirective> = []
Not documented.
field explicitStart
explicitStart: Bool = false
Whether the document starts with ---.
field explicitEnd
explicitEnd: Bool = false
Whether the document ends with ....
field leadingComments
leadingComments: List<String> = []
The comment lines before the document's first line of content.
field endComments
endComments: List<String> = []
The comment lines after the root node.
fn isVersion11
fn isVersion11(): Bool
Whether YAML 1.1's rules read this document: it says %YAML 1.1.