Improved handling of nested arrays

This commit is contained in:
moandji.ezana 2014-08-12 13:02:46 +02:00
parent 01f2ff7d76
commit 6b67baf3bf
5 changed files with 30 additions and 3 deletions

View file

@ -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() {

View file

@ -141,7 +141,6 @@ public class BurntSushiTest {
}
@Test
@Ignore
public void arrays_hetergeneous() throws Exception {
runValidTest("arrays-hetergeneous");
}

View file

@ -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");

View file

@ -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"}
]}
]
}
}

View file

@ -0,0 +1 @@
mixed = [[1, 2], ["a", "b"], [1.0, 2.0]]