mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Table array name parsing no longer handled by Parboiled
This commit is contained in:
parent
537c75757e
commit
f804c99534
3 changed files with 33 additions and 17 deletions
|
@ -65,6 +65,38 @@ class Keys {
|
|||
|
||||
return splitKey.toArray(new Key[0]);
|
||||
}
|
||||
|
||||
static String getTableArrayName(String line) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] chars = line.toCharArray();
|
||||
boolean quoted = false;
|
||||
boolean terminated = false;
|
||||
|
||||
for (int i = 2; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
if (c == '"' && chars[i - 1] != '\\') {
|
||||
quoted = !quoted;
|
||||
} else if (!quoted && c == ']') {
|
||||
if (chars.length > i + 1 && chars[i + 1] == ']') {
|
||||
terminated = true;
|
||||
break;
|
||||
}
|
||||
} else if (!quoted && (ALLOWED_CHARS.indexOf(c) == -1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
String tableName = sb.toString();
|
||||
|
||||
if (!terminated || tableName.isEmpty() || !isComment(line.substring(tableName.length() + 4))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tableName = StringConverter.STRING_PARSER.replaceUnicodeCharacters(tableName);
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line trimmed TOML line to parse
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.moandjiezana.toml;
|
||||
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.INVALID;
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.parse;
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.parser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class TomlParser {
|
||||
|
@ -173,12 +170,7 @@ class TomlParser {
|
|||
}
|
||||
|
||||
private String getTableArrayName(String line) {
|
||||
List<Object> resultValue = parse(parser().TableArray(), line);
|
||||
if (resultValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (String) resultValue.get(0);
|
||||
return Keys.getTableArrayName(line);
|
||||
}
|
||||
|
||||
private boolean isTable(String line) {
|
||||
|
|
|
@ -10,10 +10,6 @@ import org.parboiled.annotations.BuildParseTree;
|
|||
@BuildParseTree
|
||||
class ValueParser extends BaseParser<List<Object>> {
|
||||
|
||||
public Rule T() {
|
||||
return Sequence("'''", OneOrMore(TestNot("'''"), ANY), "'''", Comment());
|
||||
}
|
||||
|
||||
public Rule Array() {
|
||||
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));
|
||||
}
|
||||
|
@ -22,10 +18,6 @@ class ValueParser extends BaseParser<List<Object>> {
|
|||
return Sequence('[', startList(), Sequence(OneOrMore(NoneOf("[]")), pushToken(match())), ']', endList(), Comment());
|
||||
}
|
||||
|
||||
public Rule TableArray() {
|
||||
return Sequence('[', '[', startList(), Sequence(OneOrMore(NoneOf("[]")), pushToken(match())), ']', ']', endList(), FirstOf(EOI, Sequence(TestNot(']'), ANY)));
|
||||
}
|
||||
|
||||
public Rule LiteralString() {
|
||||
return FirstOf(EmptyLiteralString(), Sequence('\'', OneOrMore(TestNot("'"), ANY), startList(), pushToken(match()) , '\'', endList(), Comment()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue