feat: array of tables support
This commit is contained in:
parent
68c3a646c8
commit
6a2b2062b3
@ -178,7 +178,29 @@ class TomlReader : BasicParser {
|
|||||||
}
|
}
|
||||||
char c = nextChar();
|
char c = nextChar();
|
||||||
if (c == '[') {
|
if (c == '[') {
|
||||||
|
if (hasNext() && peek() == '[') {
|
||||||
|
pos++;
|
||||||
|
// parse list of tables
|
||||||
|
dv::value& list = parseLValue(root);
|
||||||
|
if (list == nullptr) {
|
||||||
|
list = dv::list();
|
||||||
|
} else if (!list.isList()) {
|
||||||
|
throw error("target is not an array");
|
||||||
|
}
|
||||||
|
expect(']');
|
||||||
|
expect(']');
|
||||||
|
dv::value section = dv::object();
|
||||||
|
readSection(section, root);
|
||||||
|
list.add(std::move(section));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// parse table
|
||||||
dv::value& section = parseLValue(root);
|
dv::value& section = parseLValue(root);
|
||||||
|
if (section == nullptr) {
|
||||||
|
section = dv::object();
|
||||||
|
} else if (!section.isObject()) {
|
||||||
|
throw error("target is not a table");
|
||||||
|
}
|
||||||
expect(']');
|
expect(']');
|
||||||
readSection(section, root);
|
readSection(section, root);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -74,7 +74,14 @@ inline std::string SRC_EXAMPLE =
|
|||||||
"[servers.beta]\n"
|
"[servers.beta]\n"
|
||||||
"ip = \"10.0.0.2\"\n"
|
"ip = \"10.0.0.2\"\n"
|
||||||
"role = \"\"\"back\\\n"
|
"role = \"\"\"back\\\n"
|
||||||
"end\"\"\"";
|
"end\"\"\"\n"
|
||||||
|
"\n"
|
||||||
|
"[[users]]\n"
|
||||||
|
"name = \"noname\"\n"
|
||||||
|
"\n"
|
||||||
|
"[[users]]\n"
|
||||||
|
"name = \"user1\"\n"
|
||||||
|
"suspended = true\n";
|
||||||
|
|
||||||
TEST(TOML, ExampleCode) {
|
TEST(TOML, ExampleCode) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user