Uses the event parser to parse TOML into a tree in memory.
Code Map
//! Uses the event parser to parse TOML into a tree in memory.
module watt.toml.tree;
//! A TOML Value.
class Value
{
public:
//! Each TOML Value is typed with one of these types.
enum Type
{
//! A series of characters.
String,
//! A 64 bit signed integer.
Integer,
//! A 64 bit floating point number.
Float,
//! A boolean value is true or false.
Boolean,
//! An array of Values of the same type.
Array,
//! A table of Values, indexed by string.
Table,
}
public:
//! The type of this Value.
type: Type;
//! Any comments that appeared before this value.
comment: string;
//! If this is a table, was it inline? (Affects toString functions).
inline: bool;
//! If this is an array, should it appear before the table it's nested in?
hoist: bool;
public:
//! Construct a Value with no type.
this() { }
//! Construct a Value with a string type.
this(v: string) { }
//! Construct a Value with an integer type.
this(v: i64) { }
//! Construct a Value with an integer type.
this(v: i32) { }
//! Construct a Value with a floating point type.
this(v: f64) { }
//! Construct a Value with a boolean type.
this(v: bool) { }
//! Construct an array of Values.
this(v: Value[]) { }
//! Get the keys for this table.
fn tableKeys() string[] { }
//! Get the Values set for this table.
fn tableValues() Value[] { }
//! If this is a table, remove the given key, if it is set.
fn removeKey(key: string) { }
//! Get a string representation of the value.
fn toString() string { }
//! Add the string representation of this Value to the given sink.
fn toString(sink: scope (sink.Sink), parent: string) { }
//! Retrieve the string value.
fn str() string { }
//! Set the string value.
fn str(val: string) { }
//! Retrieve the integer value.
fn integer() i64 { }
fn integer(val: i64) { }
//! Retrieve the floating value.
fn floating() f64 { }
//! Set the floating value.
fn floating(val: f64) { }
//! Retrieve the boolean value.
fn boolean() bool { }
//! Set the boolean value.
fn boolean(val: bool) { }
//! Retrieve the array value.
fn array() Value[] { }
//! Set a table entry.
fn tableEntry(k: string, v: Value) { }
//! Set the array value.
fn array(vals: Value[]) { }
//! How many keys does this table have set?
fn countKeys() size_t { }
//! Does this table have a key?
fn hasKey(key: string) bool { }
//! Retrieve a key from this table.
fn opIndex(key: string) Value { }
}
//! Given a TOML document, return a Value that represents that document.
fn parse(src: string) Value { }
A TOML Value.
watt.toml
treats tables as a value, and thus represents the
entire document as a table.
Each TOML Value
is typed with one of these types.
The TOML spec also specifies a date type, but the watt TOML parser does not support and has no plans to support this type.
A series of characters.
A 64 bit signed integer.
A 64 bit floating point number.
A boolean value is true
or false
.
An array of Value
s of the same type.
A table of Value
s, indexed by string.
The type of this Value
.
Any comments that appeared before this value.
If this is a table, was it inline? (Affects toString
functions).
If this is an array, should it appear before the table it's nested in?
Construct a Value
with no type.
Construct a Value
with a string type.
Construct a Value
with an integer type.
Construct a Value
with an integer type.
Construct a Value
with a floating point type.
Construct a Value
with a boolean type.
Construct an array of Value
s.
Throws
-
TomlException
if any of the givenValue
s do not have the same type.
Get the keys for this table.
Corresponds to the array returned by tableValues
.
Throws
-
TomlException
if thisValue
is not a table.
Get the Values set for this table.
Corresponds to the array return by tableKeys
.
Throws
-
TomlException
if thisValue
is not a table.
If this is a table, remove the given key, if it is set.
No operation is performed if the key is not set.
Throws
-
TomlException
if thisValue
is not a table.
Get a string representation of the value.
This is intended for serialisation of the data. e.g. Reading in a document, modifying it, and then using the output of this function to write back to disk.
The string returned will be a valid TOML document.
Note that this does not get an individual string value.
Use str
for that.
Limitations
This will try to handle implicitly defined tables gracefully, and maintain the structure as given, but complicated cascading nested tables are likely to generate bugs.
In particular, a setup like this:
[a.b.c]
x = 1
[a.b]
y = 2
[a]
z = 3
Will cause problems. To work around this issue, declare tables in the regular order (parent -> child) instead:
[a]
z = 3
[a.b]
y = 2
[a.b.c]
x = 1
Add the string representation of this Value
to the given sink.
The parent
parameter is for setting what table a sub table belongs to,
and in most user code should be left blank.
Use str
to get the string value of a key.
Retrieve the string value.
To get a printable string of any value type, or entire table,
use toString
. This is for retrieving the string value of
a String
typed toml value.
Throws
-
TomlException
if thisValue
isn't a string.
Set the string value.
Throws
-
TomlException
if thisValue
isn't a string.
Retrieve the integer value.
Throws
-
TomlException
if thisValue
isn't an integer.
Retrieve the floating value.
Throws
-
TomlException
if thisValue
isn't a float.
Set the floating value.
Throws
-
TomlException
if thisValue
isn't a float.
Retrieve the boolean value.
Throws
-
TomlException
if thisValue
isn't a boolean.
Set the boolean value.
Throws
-
TomlException
if thisValue
isn't a boolean.
Retrieve the array value.
Throws
-
TomlException
if thisValue
isn't an array.
Set a table entry.
Throws
-
TomlException
if thisValue
isn't an array.
Set the array value.
Throws
-
TomlException
if thisValue
isn't an array, or if the array is mistyped.
How many keys does this table have set?
Return
The number of keys that have been set.
Throws
-
TomlExeption
if thisValue
isn't a table.
Does this table have a key?
Return
true
if the key is set.
Throws
-
TomlException
if thisValue
isn't a table.
Retrieve a key from this table.
Throws
-
TomlException
if the key isn't set, or this isn't a table.
Given a TOML document, return a Value
that represents that document.
The returned Value
will be a table.