dyaml.loader

Class and convenience functions used to load YAML documents.

Node load(in string filename);

Load single YAML document from a file.

If there is no or more than one YAML document in the file, this will throw. Use loadAll for such files.

Parameters:
string filename Name of the file to load from.
Returns:
Root node of the document.
Throws:
YAMLException if there wasn't exactly one document in the file, the file could not be opened or on a YAML parsing error.
Node load(Stream input, in string name = "<unknown>");

Load single YAML document from a stream.

You can use this to e.g load YAML from memory.
If there is no or more than one YAML document in the stream, this will throw. Use loadAll for such files.

Parameters:
Stream input Stream to read from. Must be readable.
string name Name of the stream, used in error messages.
Returns:
Root node of the document.
Throws:
YAMLException if there wasn't exactly one document in the stream, the stream could not be read from or on a YAML parsing error.
Examples:
Loading YAML from memory:
 import std.stream;
 import std.stdio;

 string yaml_input = "red:   '#ff0000'\n"
                     "green: '#00ff00'\n"
                     "blue:  '#0000ff'";

 auto colors = yaml.load(new MemoryStream(cast(char[])yaml_input));

 foreach(string color, string value; colors)
 {
     writeln(color, " is ", value, " in HTML/CSS");
 }
Node[] loadAll(in string filename);

Load all YAML documents from a file.

Parameters:
string filename Name of the file to load from.
Returns:
Array of root nodes of documents in the stream. If the stream is empty, empty array will be returned.
Throws:
YAMLException if the file could not be opened or on a YAML parsing error.
Node[] loadAll(Stream input, in string name = "<unknown>");

Load all YAML documents from a stream.

Parameters:
Stream input Stream to read from. Must be readable.
string name Name of the stream, used in error messages.
Returns:
Array of root nodes of documents in the file. If the file is empty, empty array will be returned.
Throws:
YAMLException if the stream could not be read from or on a YAML parsing error.
struct Loader;

Loads YAML documents from files or streams.

this(in string filename);

Construct a Loader to load YAML from a file.

Parameters:
string filename Name of the file to load from.
Throws:
YAMLException if the file could not be opened or read from.
this(in string filename, Constructor constructor, Resolver resolver);

Construct a Loader to load YAML from a file, with provided constructor and resolver.

Constructor and resolver can be used to implement custom data types in YAML.

Parameters:
string filename Name of the file to load from.
Constructor constructor Constructor to use.
Resolver resolver Resolver to use.
Throws:
YAMLException if the file could not be opened or read from.
this(Stream input, in string name, Constructor constructor, Resolver resolver);

Construct a Loader to load YAML from a stream with provided constructor and resolver.

Stream can be used to load YAML from memory and other sources. Constructor and resolver can be used to implement custom data types in YAML.

Parameters:
Stream input Stream to read from. Must be readable.
string name Name of the stream. Used in error messages.
Constructor constructor Constructor to use.
Resolver resolver Resolver to use.
Throws:
YAMLException if the stream could not be read from.
Node loadSingleDocument();

Load single YAML document.

If no or more than one YAML document is found, this will throw a YAMLException.

Returns:
Root node of the document.
Throws:
YAMLException if there wasn't exactly one document or on a YAML parsing error.
int opApply(int delegate(ref Node) dg);

Foreach over YAML documents.

Parses documents lazily, as they are needed.

Throws:
YAMLException on a parsing error.