mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Improved handling of nested arrays
This commit is contained in:
parent
01f2ff7d76
commit
6b67baf3bf
5 changed files with 30 additions and 3 deletions
|
@ -18,7 +18,7 @@ public class ParboiledParser extends BaseParser<List<Object>> {
|
|||
public static void main(String[] args) {
|
||||
ParboiledParser parser = Parboiled.createParser(ParboiledParser.class);
|
||||
|
||||
ParsingResult<List<Object>> parsingResult = new RecoveringParseRunner<List<Object>>(parser.Array()).run("[[1], []]");
|
||||
ParsingResult<List<Object>> parsingResult = new RecoveringParseRunner<List<Object>>(parser.Array()).run("[ [], []]");
|
||||
System.out.println(ParseTreeUtils.printNodeTree(parsingResult));
|
||||
|
||||
System.out.println(parsingResult.resultValue);
|
||||
|
@ -26,7 +26,7 @@ public class ParboiledParser extends BaseParser<List<Object>> {
|
|||
}
|
||||
|
||||
public Rule Array() {
|
||||
return FirstOf(EmptyArray(), Sequence('[', startList(), NonEmptyArray(), ']', endList()));
|
||||
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));
|
||||
}
|
||||
|
||||
public Rule Table() {
|
||||
|
|
|
@ -141,7 +141,6 @@ public class BurntSushiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void arrays_hetergeneous() throws Exception {
|
||||
runValidTest("arrays-hetergeneous");
|
||||
}
|
||||
|
|
|
@ -75,6 +75,14 @@ public class TomlTest {
|
|||
assertEquals(asList(asList("gamma", "delta"), asList(1L, 2L)), clients.getList("data", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void should_get_nested_arrays_with_no_space_between_outer_and_inner_array() throws Exception {
|
||||
Toml clients = new Toml().parse("data = [[\"gamma\", \"delta\"], [1, 2]] # just an update to make sure parsers support it");
|
||||
|
||||
assertEquals(asList(asList("gamma", "delta"), asList(1L, 2L)), clients.getList("data", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_boolean() throws Exception {
|
||||
Toml toml = new Toml().parse("bool_false = false\nbool_true = true");
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"mixed": {
|
||||
"type": "array",
|
||||
"value": [
|
||||
{"type": "array", "value": [
|
||||
{"type": "integer", "value": "1"},
|
||||
{"type": "integer", "value": "2"}
|
||||
]},
|
||||
{"type": "array", "value": [
|
||||
{"type": "string", "value": "a"},
|
||||
{"type": "string", "value": "b"}
|
||||
]},
|
||||
{"type": "array", "value": [
|
||||
{"type": "float", "value": "1.0"},
|
||||
{"type": "float", "value": "2.0"}
|
||||
]}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
mixed = [[1, 2], ["a", "b"], [1.0, 2.0]]
|
Loading…
Reference in a new issue