Literal strings no longer handled by Parboiled

This commit is contained in:
moandji.ezana 2015-01-23 16:36:15 +02:00
parent bde639951a
commit 40cab5c499
2 changed files with 28 additions and 11 deletions

View file

@ -1,9 +1,7 @@
package com.moandjiezana.toml;
import static com.moandjiezana.toml.ValueConverterUtils.parse;
import static com.moandjiezana.toml.ValueConverterUtils.parser;
import static com.moandjiezana.toml.ValueConverterUtils.INVALID;
import java.util.List;
class LiteralStringConverter implements ValueConverter {
@ -16,13 +14,36 @@ class LiteralStringConverter implements ValueConverter {
@Override
public Object convert(String s) {
List<String> resultValue = parse(parser().LiteralString(), s);
char[] chars = s.toCharArray();
boolean terminated = false;
StringBuilder sb = new StringBuilder(s.length());
if (resultValue == null) {
return ValueConverterUtils.INVALID;
for (int i = 1; i < chars.length; i++) {
char c = chars[i];
if (c == '\'') {
terminated = true;
continue;
}
return resultValue.get(0);
if (!terminated) {
sb.append(c);
}
if (terminated && c == '#') {
break;
}
if (terminated && !Character.isWhitespace(c)) {
return INVALID;
}
}
if (!terminated) {
return INVALID;
}
return sb.toString();
}
private LiteralStringConverter() {}

View file

@ -14,10 +14,6 @@ class ValueParser extends BaseParser<List<Object>> {
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));
}
public Rule LiteralString() {
return FirstOf(EmptyLiteralString(), Sequence('\'', OneOrMore(TestNot("'"), ANY), startList(), pushToken(match()) , '\'', endList(), Comment()));
}
public Rule MultilineLiteralString() {
return FirstOf(EmptyMultilineLiteralString(), Sequence("'''", startList(), Sequence(OneOrMore(TestNot("'''"), ANY), pushToken(match())), "'''", endList(), Comment()));
}