Module yaml/dom
Dark Mode
Search:
Group by:
-
Imports
- Types
-
Procs
- `[]`(node: YamlNode; i: int): YamlNode
- `[]`(node: YamlNode; key: string): YamlNode
- `[]`(node: YamlNode; key: YamlNode): YamlNode
- `[]=`(node: var YamlNode; i: int; val: YamlNode)
- `[]=`(node: YamlNode; key: YamlNode; value: YamlNode)
- initYamlDoc(root: YamlNode): YamlDocument
- loadMultiDom(s: Stream | string): seq[YamlDocument]
- []
- []=
- initYamlDoc
- loadMultiDom
- Iterators
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
YamlDocument = object root*: YamlNode
- Represents a YAML document.
YamlNode = ref YamlNodeObj not nil
- Represents a node in a YamlDocument.
YamlNodeKind = enum yScalar, yMapping, ySequence
YamlNodeObj = object tag*: Tag case kind*: YamlNodeKind of yScalar: content*: string of ySequence: elems*: seq[YamlNode] of yMapping: fields*: TableRef[YamlNode, YamlNode]
Procs
proc `$`(n: YamlNode): string {....raises: [], tags: [].}
proc `==`(x, y: YamlNode): bool {....raises: [], tags: [].}
proc `[]=`(node: var YamlNode; i: int; val: YamlNode) {....raises: [], tags: [].}
- Set the node at index i of a sequence. node must be a ySequence.
proc `[]=`(node: YamlNode; key: YamlNode; value: YamlNode) {....raises: [], tags: [].}
- Set the value for a key in a mapping. node must be a yMapping.
proc `[]`(node: YamlNode; i: int): YamlNode {....raises: [], tags: [].}
- Get the node at index i from a sequence. node must be a ySequence.
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.
proc `[]`(node: YamlNode; key: YamlNode): YamlNode {....raises: [KeyError], tags: [].}
proc compose(s: var YamlStream): YamlDocument {. ...raises: [YamlStreamError, YamlConstructionError], tags: [RootEffect].}
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.
proc hash(o: YamlNode): Hash {....raises: [], tags: [].}
proc initYamlDoc(root: YamlNode): YamlDocument {....raises: [], tags: [].}
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
proc loadDom(s: Stream | string): YamlDocument {. ...raises: [IOError, OSError, YamlParserError, YamlConstructionError].}
proc loadMultiDom(s: Stream | string): seq[YamlDocument] {. ...raises: [IOError, OSError, YamlParserError, YamlConstructionError].}
proc newYamlNode(content: string; tag: Tag = yTagQuestionMark): YamlNode {. ...raises: [], tags: [].}
proc newYamlNode(elems: openArray[YamlNode]; tag: Tag = yTagQuestionMark): YamlNode {. ...raises: [], tags: [].}
proc newYamlNode(fields: openArray[(YamlNode, YamlNode)]; tag: Tag = yTagQuestionMark): YamlNode {....raises: [], tags: [].}
proc serialize(doc: YamlDocument; a: AnchorStyle = asTidy): YamlStream {. ...raises: [], tags: [RootEffect].}
Iterators
iterator items(node: YamlNode): YamlNode {....raises: [], tags: [].}
- Iterates over all items of a sequence. node must be a ySequence.
iterator mitems(node: var YamlNode): YamlNode {....raises: [], tags: [].}
- Iterates over all items of a sequence. node must be a ySequence. Values can be modified.
iterator mpairs(node: var YamlNode): tuple[key: YamlNode, value: var YamlNode] {. ...raises: [], tags: [].}
- Iterates over all key-value pairs of a mapping. node must be a yMapping. Values can be modified.
iterator pairs(node: YamlNode): tuple[key, value: YamlNode] {....raises: [], tags: [].}
- Iterates over all key-value pairs of a mapping. node must be a yMapping.