use of pcgen.core.kit.KitGear in project pcgen by PCGen.
the class ValuesToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitTable kitTable, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
while (sep.hasNext()) {
String thing = sep.next();
if (thing.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " arguments has invalid pipe separator: " + value, context);
}
KitGear optionInfo = new KitGear();
for (String s : thing.split("[\\[\\]]")) {
if (s.isEmpty()) {
continue;
}
int colonLoc = s.indexOf(':');
if (colonLoc == -1) {
return new ParseResult.Fail("Expected colon in Value item: " + s + " within: " + value, context);
}
String key = s.substring(0, colonLoc);
String thingValue = s.substring(colonLoc + 1);
try {
boolean passed = context.processToken(optionInfo, key, thingValue);
if (!passed) {
return new ParseResult.Fail("Failure in token: " + key, context);
}
} catch (PersistenceLayerException e) {
return new ParseResult.Fail("Failure in token: " + key + " " + e.getMessage(), context);
}
}
if (!sep.hasNext()) {
return new ParseResult.Fail("Odd token count in Value: " + value, context);
}
String range = sep.next();
if (!processRange(kitTable, optionInfo, range)) {
return new ParseResult.Fail("Invalid Range in Value: " + range + " within " + value, context);
}
}
return ParseResult.SUCCESS;
}
Aggregations