Module yaml.dom
Search:
Group by:
This is the DOM API, which enables you to load YAML into a tree-like structure. It can also dump the structure back to YAML. Formally, it represents the Representation Graph as defined in the YAML specification.
The main interface of this API are loadDom and dumpDom. The other exposed procs are low-level and useful if you want to load or generate parts of a YamlStream.
The YamlNode objects in the DOM can be used similarly to the JsonNode objects of Nim's json module.
Imports
Types
YamlNodeKind = enum yScalar, yMapping, ySequence
- Source
YamlNode = ref YamlNodeObj not nil
- Represents a node in a YamlDocument. Source
YamlNodeObj = object tag*: string case kind*: YamlNodeKind of yScalar: content*: string of ySequence: elems*: seq[YamlNode] of yMapping: fields*: TableRef[YamlNode, YamlNode]
- Source
YamlDocument = object root*: YamlNode
- Represents a YAML document. Source
Procs
proc hash(o: YamlNode): Hash {.
raises: [], tags: [].}- Source
proc `==`(x, y: YamlNode): bool {.
raises: [], tags: [].}- Source
proc `$`(n: YamlNode): string {.
raises: [], tags: [].}- Source
proc newYamlNode(content: string; tag: string = "?"): YamlNode {.
raises: [], tags: [].}- Source
proc newYamlNode(elems: openArray[YamlNode]; tag: string = "?"): YamlNode {.
raises: [], tags: [].}- Source
proc newYamlNode(fields: openArray[(YamlNode, YamlNode)]; tag: string = "?"): YamlNode {.
raises: [], tags: [].}- Source
proc initYamlDoc(root: YamlNode): YamlDocument {.
raises: [], tags: [].}- Source
proc compose(s: var YamlStream; tagLib: TagLibrary): YamlDocument {.
raises: [YamlStreamError, YamlConstructionError], tags: [WriteIOEffect, RootEffect].}- Source
proc loadDom(s: Stream | string): YamlDocument {.
raises: [IOError, YamlParserError, YamlConstructionError].}- Source
proc serialize(doc: YamlDocument; tagLib: TagLibrary; a: AnchorStyle = asTidy): YamlStream {.
raises: [], tags: [RootEffect].}- Source
proc dumpDom(doc: YamlDocument; target: Stream; anchorStyle: AnchorStyle = asTidy; options: PresentationOptions = defaultPresentationOptions) {.
raises: [ YamlPresenterJsonError, YamlPresenterOutputError, YamlStreamError], tags: [RootEffect, WriteIOEffect].}- Dump a YamlDocument as YAML character stream. Source
proc `[]`(node: YamlNode; i: int): YamlNode {.
raises: [], tags: [].}- Get the node at index i from a sequence. node must be a ySequence. Source
proc `[]=`(node: var YamlNode; i: int; val: YamlNode) {.
raises: [], tags: [].}- Set the node at index i of a sequence. node must be a ySequence. Source
proc `[]`(node: YamlNode; key: YamlNode): YamlNode {.
raises: [KeyError], tags: [].}- Get the value for a key in a mapping. node must be a yMapping. Source
proc `[]=`(node: YamlNode; key: YamlNode; value: YamlNode) {.
raises: [], tags: [].}- Set the value for a key in a mapping. node must be a yMapping. Source
proc `[]`(node: YamlNode; key: string): YamlNode {.
raises: [KeyError], tags: [].}- Get the value for a string key in a mapping. node must be a yMapping. This searches for a scalar key with content key and either no explicit tag or the explicit tag !!str. Source
proc len(node: YamlNode): int {.
raises: [], tags: [].}- If node is a yMapping, return the number of key-value pairs. If node is a ySequence, return the number of elements. Else, return 0 Source
Iterators
iterator items(node: YamlNode): YamlNode {.
raises: [], tags: [].}- Iterates over all items of a sequence. node must be a ySequence. Source
iterator mitems(node: var YamlNode): YamlNode {.
raises: [], tags: [].}- Iterates over all items of a sequence. node must be a ySequence. Values can be modified. Source
iterator pairs(node: YamlNode): tuple[key, value: YamlNode] {.
raises: [], tags: [].}- Iterates over all key-value pairs of a mapping. node must be a yMapping. Source
iterator mpairs(node: var YamlNode): tuple[key: YamlNode, value: var YamlNode] {.
raises: [AssertionError], tags: [].}- Iterates over all key-value pairs of a mapping. node must be a yMapping. Values can be modified. Source