use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class DefineLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String firstItem = sep.next();
if (firstItem.startsWith("UNLOCK.")) {
return new ParseResult.Fail("DEFINE:UNLOCK. has been deprecated, " + "please use DEFINESTAT:STAT| or DEFINESTAT:UNLOCK|", context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " varName|varFormula" + "or LOCK.<stat>|value syntax requires an argument", context);
}
String var = firstItem;
if (var.isEmpty()) {
return new ParseResult.Fail("Empty Variable Name found in " + getTokenName() + ": " + value, context);
}
try {
Formula f = FormulaFactory.getFormulaFor(sep.next());
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
if ((!f.isStatic() || f.resolveStatic().intValue() != 0) && !(var.startsWith("MAXLEVELSTAT="))) {
Logging.deprecationPrint("DEFINE with a non zero value has been deprecated, " + "please use a DEFINE of 0 and an appropriate bonus. Tag was DEFINE:" + value + " in " + obj, context);
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + ' ' + firstItem + " syntax requires only one argument: " + value, context);
}
if (value.startsWith("LOCK.")) {
return new ParseResult.Fail("DEFINE:LOCK. has been deprecated, " + "please use DEFINESTAT:LOCL| or DEFINESTAT:NONSTAT|", context);
} else {
context.getObjectContext().put(obj, VariableKey.getConstant(var), f);
}
return ParseResult.SUCCESS;
} catch (IllegalArgumentException e) {
return new ParseResult.Fail("Illegal Formula found in " + getTokenName() + ": " + value + ' ' + e.getLocalizedMessage(), context);
}
}
use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class DefineStatLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String firstItem = sep.next();
DefineStatSubToken subToken;
try {
subToken = DefineStatSubToken.valueOf(firstItem);
} catch (IllegalArgumentException e1) {
return new ParseResult.Fail("Found unexpected sub tag " + firstItem + " in " + getTokenName() + Constants.COLON + value + ". Must be one of " + StringUtils.join(DefineStatSubToken.values(), ", ") + Constants.DOT, context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + subToken + "| must be followed by a stat.", context);
}
String statKey = sep.next();
CDOMSingleRef<PCStat> stat = context.getReferenceContext().getCDOMReference(PCSTAT_CLASS, statKey);
Formula f = null;
if (subToken == DefineStatSubToken.LOCK || subToken == DefineStatSubToken.MINVALUE || subToken == DefineStatSubToken.MAXVALUE) {
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + subToken + "| must be followed by both a stat and a value.", context);
}
String formula = sep.next();
f = FormulaFactory.getFormulaFor(formula);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + value + " has too many pipe separated item.", context);
}
switch(subToken) {
case LOCK:
context.getObjectContext().addToList(obj, ListKey.STAT_LOCKS, new StatLock(stat, f));
break;
case UNLOCK:
context.getObjectContext().addToList(obj, ListKey.UNLOCKED_STATS, stat);
break;
case NONSTAT:
context.getObjectContext().addToList(obj, ListKey.NONSTAT_STATS, stat);
break;
case STAT:
context.getObjectContext().addToList(obj, ListKey.NONSTAT_TO_STAT_STATS, stat);
break;
case MINVALUE:
context.getObjectContext().addToList(obj, ListKey.STAT_MINVALUE, new StatLock(stat, f));
break;
case MAXVALUE:
context.getObjectContext().addToList(obj, ListKey.STAT_MAXVALUE, new StatLock(stat, f));
break;
}
return ParseResult.SUCCESS;
}
use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.
the class FollowersLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if ((value == null) || value.isEmpty()) {
return new ParseResult.Fail("Argument in " + getTokenName() + " cannot be empty", context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String followerType = sep.next();
if (followerType.isEmpty()) {
return new ParseResult.Fail("Follower Type in " + getTokenName() + " cannot be empty", context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " has no PIPE character: " + "Must be of the form <follower type>|<formula>", context);
}
String followerNumber = sep.next();
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " has too many PIPE characters: " + "Must be of the form <follower type>|<formula", context);
}
if (followerNumber.isEmpty()) {
return new ParseResult.Fail("Follower Count in " + getTokenName() + " cannot be empty", context);
}
CDOMSingleRef<CompanionList> cl = context.getReferenceContext().getCDOMReference(CompanionList.class, followerType);
Formula num = FormulaFactory.getFormulaFor(followerNumber);
if (!num.isValid()) {
return new ParseResult.Fail("Number of Followers in " + getTokenName() + " was not valid: " + num.toString(), context);
}
context.getObjectContext().addToList(obj, ListKey.FOLLOWERS, new FollowerLimit(cl, num));
return ParseResult.SUCCESS;
}
use of pcgen.base.text.ParsingSeparator 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.base.text.ParsingSeparator 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;
}
Aggregations