use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class AddFeatToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String addType = sep.next();
if (!"FEAT".equals(addType)) {
return new ParseResult.Fail("Incompatible with ADD:FEAT:" + value);
}
String activeValue = sep.next();
Formula count;
if (!sep.hasNext()) {
count = FormulaFactory.ONE;
} else {
count = FormulaFactory.getFormulaFor(activeValue);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
return new ParseResult.Fail("Count in ADD:FEAT must be > 0", context);
}
activeValue = sep.next();
}
if (sep.hasNext()) {
return new ParseResult.Fail("ADD:FEAT had too many pipe separated items: " + value, context);
}
try {
if (!context.processToken(obj, "ADD", "ABILITY|" + count.toString() + "|FEAT|NORMAL|" + activeValue)) {
Logging.replayParsedMessages();
return new ParseResult.Fail("Delegation Error from ADD:FEAT");
}
} catch (PersistenceLayerException e) {
return new ParseResult.Fail("Delegation Error from ADD:FEAT: " + e.getLocalizedMessage());
}
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class AddVFeatToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String addType = sep.next();
if (!"VFEAT".equals(addType)) {
return new ParseResult.Fail("Incompatible with ADD:VFEAT: " + value);
}
String activeValue = sep.next();
Formula count;
if (!sep.hasNext()) {
count = FormulaFactory.ONE;
} else {
count = FormulaFactory.getFormulaFor(activeValue);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
return new ParseResult.Fail("Count in ADD:VFEAT must be > 0", context);
}
activeValue = sep.next();
}
if (sep.hasNext()) {
return new ParseResult.Fail("ADD:VFEAT had too many pipe separated items: " + value, context);
}
try {
if (!context.processToken(obj, "ADD", "ABILITY|" + count.toString() + "|FEAT|VIRTUAL|" + activeValue)) {
Logging.replayParsedMessages();
return new ParseResult.Fail("Delegation Error from ADD:VFEAT");
}
} catch (PersistenceLayerException e) {
return new ParseResult.Fail("Delegation Error from ADD:VFEAT: " + e.getLocalizedMessage());
}
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class VisibleToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, ContentDefinition factDef, String value) {
Visibility vis;
if (value.equals("YES")) {
vis = Visibility.DEFAULT;
} else if (value.equals("DISPLAY")) {
vis = Visibility.DISPLAY_ONLY;
} else if (value.equals("EXPORT")) {
vis = Visibility.OUTPUT_ONLY;
} else if (value.equals("NO")) {
vis = Visibility.HIDDEN;
} else {
return new ParseResult.Fail("Unable to understand " + getTokenName() + " tag: " + value, context);
}
factDef.setVisibility(vis);
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class UserInputToken method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
UserChooseInformation ci = new UserChooseInformation();
if (value != null) {
int pipeLoc = value.indexOf('|');
String titleString;
if (pipeLoc == -1) {
titleString = value;
} else {
String countString = value.substring(0, pipeLoc);
Logging.deprecationPrint("CHOOSE:USERINPUT with count is deprecated, " + "please use SELECT: to identify the quantity of selections", context);
int firstarg;
try {
firstarg = Integer.parseInt(countString);
} catch (NumberFormatException nfe) {
return new ParseResult.Fail("If CHOOSE:" + getTokenName() + " contains a pipe, " + "first argument must be an Integer : " + value, context);
}
Formula count = FormulaFactory.getFormulaFor(firstarg);
context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, count);
context.getObjectContext().put(obj, FormulaKey.SELECT, count);
titleString = value.substring(pipeLoc + 1);
}
if (!titleString.startsWith("TITLE=")) {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " in " + obj.getClass() + " " + obj.getKeyName() + " had invalid arguments: " + value, context);
}
String title = titleString.substring(6);
if (title.startsWith("\"")) {
title = title.substring(1, title.length() - 1);
}
ci.setTitle(title);
} else {
ci.setTitle(getDefaultTitle());
}
// No args - legal
context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, ci);
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class ExplanationTokenTest method testDisplayNameRequired.
@Test
public void testDisplayNameRequired() throws PersistenceLayerException {
DatasetVariable dv = new DatasetVariable();
ParseResult pr = token.parseToken(primaryContext, dv, "Try Me!");
assertFalse(pr.passed());
assertNoSideEffects();
}
Aggregations