Loader

Loads YAML documents from files or char[].

User specified Constructor and/or Resolver can be used to support new tags / data types.

Disabled Default Constructor

A disabled default is present on this object. To use it, use one of the other constructors or a factory function.

Constructors

this
this(string filename)

Construct a Loader to load YAML from a file.

this
this(void[] yamlData)

Construct a Loader to load YAML from a buffer.

Destructor

~this
~this()

Destroy the Loader.

Members

Functions

constructor
void constructor(Constructor constructor)

Specify custom Constructor to use.

load
Node load()

Load single YAML document.

loadAll
Node[] loadAll()

Load all YAML documents.

name
void name(string name)

Set stream name. Used in debugging messages.

opApply
int opApply(int delegate(ref Node) dg)

Foreach over YAML documents.

resolver
void resolver(Resolver resolver)

Specify custom Resolver to use.

Static functions

fromString
Loader fromString(char[] data)

Construct a Loader to load YAML from a string (char []).

Examples

Load single YAML document from a file:

auto rootNode = Loader("file.yaml").load();
...

Load all YAML documents from a file:

auto nodes = Loader("file.yaml").loadAll();
...

Iterate over YAML documents in a file, lazily loading them:

1 auto loader = Loader("file.yaml");
2 
3 foreach(ref node; loader)
4 {
5    ...
6 }

Load YAML from a string:

1 char[] yaml_input = "red:   '#ff0000'\n"
2                    "green: '#00ff00'\n"
3                    "blue:  '#0000ff'".dup;
4 
5 auto colors = Loader.fromString(yaml_input).load();
6 
7 foreach(string color, string value; colors)
8 {
9    import std.stdio;
10    writeln(color, " is ", value, " in HTML/CSS");
11 }

Load a file into a buffer in memory and then load YAML from that buffer:

1 try
2 {
3    import std.file;
4    void[] buffer = std.file.read("file.yaml");
5    auto yamlNode = Loader(buffer);
6 
7    // Read data from yamlNode here...
8 }
9 catch(FileException e)
10 {
11    writeln("Failed to read file 'file.yaml'");
12 }

Use a custom constructor/resolver to support custom data types and/or implicit tags:

1 auto constructor = new Constructor();
2 auto resolver    = new Resolver();
3 
4 // Add constructor functions / resolver expressions here...
5 
6 auto loader = Loader("file.yaml");
7 loader.constructor = constructor;
8 loader.resolver    = resolver;
9 auto rootNode      = loader.load(node);

Meta