Loader

Loads YAML documents from files or char[].

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

Constructors

this
this()
Undocumented in source.
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.

lazyInitConstructorResolver
void lazyInitConstructorResolver()
Undocumented in source. Be warned that the author may not have intended to support it.
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.

opCmp
int opCmp(Loader )
Undocumented in source.
opEquals
bool opEquals(Loader )
Undocumented in source.
parse
immutable(Event)[] parse()
Undocumented in source. Be warned that the author may not have intended to support it.
resolver
void resolver(Resolver resolver)

Specify custom Resolver to use.

scan
Token[] scan()
Undocumented in source. Be warned that the author may not have intended to support it.
scanBench
void scanBench()
Undocumented in source. Be warned that the author may not have intended to support it.

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:

auto loader = Loader("file.yaml");

foreach(ref node; loader)
{
    ...
}

Load YAML from a string:

char[] yaml_input = "red:   '#ff0000'\n"
                    "green: '#00ff00'\n"
                    "blue:  '#0000ff'".dup;

auto colors = Loader.fromString(yaml_input).load();

foreach(string color, string value; colors)
{
    import std.stdio;
    writeln(color, " is ", value, " in HTML/CSS");
}

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

try
{
    import std.file;
    void[] buffer = std.file.read("file.yaml");
    auto yamlNode = Loader(buffer);

    // Read data from yamlNode here...
}
catch(FileException e)
{
    writeln("Failed to read file 'file.yaml'");
}

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

auto constructor = new Constructor();
auto resolver    = new Resolver();

// Add constructor functions / resolver expressions here...

auto loader = Loader("file.yaml");
loader.constructor = constructor;
loader.resolver    = resolver;
auto rootNode      = loader.load(node);

Meta