use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class TableLoader method generateCSVSeparator.
/**
* Generates a new "naive" CSV separator. This is not formally CSV compliant
* because it ignores "embedded" new lines. For purposes of PCGen this is
* acceptable.
*
* @param lstLine
* The line to be processed by a CSV-like ParsingSeparator
* @return A ParsingSeparator for the given line
*/
private static ParsingSeparator generateCSVSeparator(String lstLine) {
ParsingSeparator ps = new ParsingSeparator(lstLine, ',');
ps.addGroupingPair('"', '"');
return ps;
}
use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class ChoiceSetLoadUtilities method getChoiceSet.
public static <T extends CDOMObject> PrimitiveCollection<T> getChoiceSet(LoadContext context, SelectionCreator<T> sc, String joinedOr) {
List<PrimitiveCollection<T>> orList = new ArrayList<>();
ParsingSeparator pipe = new ParsingSeparator(joinedOr, '|');
pipe.addGroupingPair('[', ']');
pipe.addGroupingPair('(', ')');
for (; pipe.hasNext(); ) {
String joinedAnd = pipe.next();
if (hasIllegalSeparator(',', joinedAnd)) {
return null;
}
List<PrimitiveCollection<T>> andList = new ArrayList<>();
ParsingSeparator comma = new ParsingSeparator(joinedAnd, ',');
comma.addGroupingPair('[', ']');
comma.addGroupingPair('(', ')');
for (; comma.hasNext(); ) {
String primitive = comma.next();
if (primitive == null || primitive.isEmpty()) {
Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was null or empty: " + primitive);
return null;
}
QualifierToken<T> qual = getQualifier(context, sc, primitive);
if (qual == null) {
PrimitiveCollection<T> pcf = getSimplePrimitive(context, sc, primitive);
if (pcf == null) {
Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was not valid: " + primitive);
return null;
} else {
andList.add(pcf);
}
} else {
andList.add(qual);
}
}
if (!andList.isEmpty()) {
if (andList.size() == 1) {
orList.add(andList.get(0));
} else {
orList.add(new CompoundAndPrimitive<>(andList));
}
}
}
if (orList.isEmpty()) {
return null;
} else if (orList.size() == 1) {
return orList.get(0);
} else {
return new CompoundOrPrimitive<>(orList);
}
}
use of pcgen.base.text.ParsingSeparator 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;
}
use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class EquipBuyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
if (looksLikeAPrerequisite(activeValue)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
Formula f = FormulaFactory.getFormulaFor(activeValue);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
List<Prerequisite> prereqs = new ArrayList<>();
while (sep.hasNext()) {
activeValue = sep.next();
Prerequisite prereq = getPrerequisite(activeValue);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
}
kit.put(ObjectKey.EQUIP_BUY, new QualifiedObject<>(f, prereqs));
return ParseResult.SUCCESS;
}
use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class TotalCostToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
if (looksLikeAPrerequisite(activeValue)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
Formula f = FormulaFactory.getFormulaFor(activeValue);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
List<Prerequisite> prereqs = new ArrayList<>();
while (sep.hasNext()) {
activeValue = sep.next();
Prerequisite prereq = getPrerequisite(activeValue);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put total costs after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
}
kit.put(ObjectKey.KIT_TOTAL_COST, new QualifiedObject<>(f, prereqs));
return ParseResult.SUCCESS;
}
Aggregations