Module yaml/dom
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)
- loadFlattened[K](input: Stream | string; target: var K)
- newYamlNode(content: string; tag: Tag = yTagQuestionMark; style: ScalarStyle = ssAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode
- newYamlNode(elems: openArray[YamlNode]; tag: Tag = yTagQuestionMark; style: CollectionStyle = csAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode
- newYamlNode(fields: openArray[(YamlNode, YamlNode)]; tag: Tag = yTagQuestionMark; style: CollectionStyle = csAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode
- []
- []=
- loadFlattened
- newYamlNode
- 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.
You use this API by importing this module alongside loading and/or dumping, and then call load() / dump() on YamlNode values. A special function loadFlattened allows you to load aliases in the YAML input as if they were copies of the referenced subtree.
The YamlNode objects in the DOM are structured similarly to the JsonNode objects of Nim's json module.
Imports
Types
YamlNode = ref YamlNodeObj
- Represents a node in a YAML document
YamlNodeKind = enum yScalar, yMapping, ySequence
YamlNodeObj = object tag*: Tag startPos*, endPos*: Mark case kind*: YamlNodeKind of yScalar: content*: string scalarStyle*: ScalarStyle of ySequence: elems*: seq[YamlNode] seqStyle*: CollectionStyle of yMapping: fields*: TableRef[YamlNode, YamlNode] mapStyle*: CollectionStyle
Procs
proc `[]`(node: YamlNode; i: int): YamlNode {....raises: [], tags: [], forbids: [].}
- Get the node at index i from a sequence. node must be a ySequence.
proc `[]`(node: YamlNode; key: string): YamlNode {....raises: [KeyError], tags: [], forbids: [].}
- 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: [], forbids: [].}
proc `[]=`(node: var YamlNode; i: int; val: YamlNode) {....raises: [], tags: [], forbids: [].}
- Set the node at index i of a sequence. node must be a ySequence.
proc `[]=`(node: YamlNode; key: YamlNode; value: YamlNode) {....raises: [], tags: [], forbids: [].}
- Set the value for a key in a mapping. node must be a yMapping.
proc constructChild(ctx: var ConstructionContext; result: var YamlNode) {. ...raises: [YamlStreamError, YamlConstructionError], tags: [RootEffect], forbids: [].}
proc len(node: YamlNode): int {....raises: [], tags: [], forbids: [].}
- 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 loadFlattened[K](input: Stream | string; target: var K) {....raises: [ YamlConstructionError, YamlSerializationError, IOError, OSError, YamlParserError].}
- Replaces all aliases with the referenced nodes in the input, then loads the resulting YAML into K. Can be used when anchors & aliases are used like variables in the input, to avoid having to define ref types for the anchored data.
proc newYamlNode(content: string; tag: Tag = yTagQuestionMark; style: ScalarStyle = ssAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode {....raises: [], tags: [], forbids: [].}
proc newYamlNode(elems: openArray[YamlNode]; tag: Tag = yTagQuestionMark; style: CollectionStyle = csAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode {....raises: [], tags: [], forbids: [].}
proc newYamlNode(fields: openArray[(YamlNode, YamlNode)]; tag: Tag = yTagQuestionMark; style: CollectionStyle = csAny; startPos: Mark = Mark(); endPos: Mark = Mark()): YamlNode {. ...raises: [], tags: [], forbids: [].}
proc representChild(ctx: var SerializationContext; value: YamlNodeObj) {. ...raises: [YamlSerializationError], tags: [RootEffect], forbids: [].}
Iterators
iterator items(node: YamlNode): YamlNode {....raises: [], tags: [], forbids: [].}
- Iterates over all items of a sequence. node must be a ySequence.
iterator mitems(node: var YamlNode): YamlNode {....raises: [], tags: [], forbids: [].}
- Iterates over all items of a sequence. node must be a ySequence. Values can be modified.