dyaml.constructor
Implements a class that processes YAML mappings, sequences and scalars into nodes. This can be used to implement custom data types. A tutorial can be found here.
- class ConstructorException: dyaml.exception.YAMLException;
Exception thrown at constructor errors.
Can be thrown by custom constructor functions.
- this(string msg, Mark start, Mark end, string file = __FILE__, int line = __LINE__);
Construct a ConstructorException.
Parameters:string msg Error message. Mark start Start position of the error context. Mark end End position of the error context.
- class Constructor;
Constructs YAML values.
Each YAML scalar, sequence or mapping has a tag specifying its data type. Constructor uses user-specifyable functions to create a node of desired data type from a scalar, sequence or mapping.
Each of these functions is associated with a tag, and can process either a scalar, a sequence, or a mapping. The constructor passes each value to the function with corresponding tag, which then returns the resulting value that can be stored in a node.
If a tag is detected with no known constructor function, it is considered an error.- this(in bool defaultConstructors = true);
Construct a Constructor.
If you don't want to support default YAML tags/data types, you can use defaultConstructors to disable constructor functions for these.
Parameters:bool defaultConstructors Use constructors for default YAML tags? - void addConstructor(T, U)(in string tag, T function(Mark, Mark, U) ctor);
Add a constructor function.
The function passed must two Marks (determining start and end positions of the node in file) and either a string (if constructing from scalar), an array of Nodes (from sequence) or an array of Node.Pair (from mapping). The value returned by this function will be stored in the resulring node.
Parameters:
Only one constructor function can be set for one tag.tag Tag for the function to handle. ctor Constructor function.
- YAMLNull constructNull(Mark start, Mark end, string value);
Construct a null node.
- YAMLMerge constructMerge(Mark start, Mark end, string value);
Construct a merge node - a node that merges another node into a mapping.
- bool constructBool(Mark start, Mark end, string value);
Construct a boolean node.
- long constructLong(Mark start, Mark end, string value);
Construct an integer (long) node.
- real constructReal(Mark start, Mark end, string value);
Construct a floating point (real) node.
- ubyte[] constructBinary(Mark start, Mark end, string value);
Construct a binary (base64) node.
- SysTime constructTimestamp(Mark start, Mark end, string value);
Construct a timestamp (SysTime) node.
- string constructString(Mark start, Mark end, string value);
Construct a string node.
- Pair[] getPairs(string type, Mark start, Mark end, Node[] nodes);
Convert a sequence of single-element mappings into a sequence of pairs.
- Pair[] constructOrderedMap(Mark start, Mark end, Node[] nodes);
Construct an ordered map (ordered sequence of key:value pairs without duplicates) node.
- Pair[] constructPairs(Mark start, Mark end, Node[] nodes);
Construct a pairs (ordered sequence of key: value pairs allowing duplicates) node.
- Node[] constructSet(Mark start, Mark end, Pair[] pairs);
Construct a set node.
- Node[] constructSequence(Mark start, Mark end, Node[] nodes);
Construct a sequence (array) node.
- Pair[] constructMap(Mark start, Mark end, Pair[] pairs);
Construct an unordered map (unordered set of key: value pairs without duplicates) node.