use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class AbstractKitTokenTestCase method parse.
public boolean parse(String str) {
ParseResult pr = getToken().parseToken(primaryContext, primaryProf, str);
if (pr.passed()) {
primaryContext.commit();
} else {
pr.addMessagesToLog();
primaryContext.rollback();
Logging.rewindParseMessages();
Logging.replayParsedMessages();
}
return pr.passed();
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class GlobalTokenTest method testDisplayNameProhibited.
@Test
public void testDisplayNameProhibited() throws PersistenceLayerException {
DatasetVariable dv = new DatasetVariable();
dv.setName("FirstName");
ParseResult pr = token.parseToken(primaryContext, dv, "VarName");
assertFalse(pr.passed());
assertNoSideEffects();
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class LocalTokenTest method testInvalidDupeVarName.
@Test
public void testInvalidDupeVarName() throws PersistenceLayerException {
DatasetVariable dv = new DatasetVariable();
ParseResult pr = token.parseToken(primaryContext, dv, "EQUIPMENT|MyVar");
assertTrue(pr.passed());
assertFalse(parse("EQUIPMENT|STRING=MyVar"));
assertNoSideEffects();
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class LocalTokenTest method testDisplayNameProhibited.
@Test
public void testDisplayNameProhibited() throws PersistenceLayerException {
DatasetVariable dv = new DatasetVariable();
dv.setName("FirstName");
ParseResult pr = token.parseToken(primaryContext, dv, "VarName");
assertFalse(pr.passed());
assertNoSideEffects();
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class AlttypeToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
EquipmentHead head = eq.getEquipmentHead(2);
if (value.startsWith(Constants.LST_DOT_CLEAR)) {
context.getObjectContext().removeList(head, ListKey.TYPE);
if (value.length() == 6) {
return ParseResult.SUCCESS;
} else if (value.charAt(6) == '.') {
value = value.substring(7);
if (isEmpty(value)) {
return new ParseResult.Fail(getTokenName() + "started with .CLEAR. but expected to have a Type after .: " + value, context);
}
} else {
return new ParseResult.Fail(getTokenName() + "started with .CLEAR but expected next character to be .: " + value, context);
}
}
ParseResult pr = checkForIllegalSeparator('.', value);
if (!pr.passed()) {
return pr;
}
StringTokenizer aTok = new StringTokenizer(value, Constants.DOT);
boolean bRemove = false;
boolean bAdd = false;
while (aTok.hasMoreTokens()) {
final String aType = aTok.nextToken();
if ("ADD".equals(aType)) {
if (bRemove) {
return new ParseResult.Fail("Non-sensical use of .REMOVE.ADD. in " + getTokenName() + ": " + value, context);
}
bRemove = false;
bAdd = true;
} else if ("REMOVE".equals(aType)) {
if (bAdd) {
return new ParseResult.Fail("Non-sensical use of .ADD.REMOVE. in " + getTokenName() + ": " + value, context);
}
bRemove = true;
} else if ("CLEAR".equals(aType)) {
return new ParseResult.Fail("Non-sensical use of .CLEAR in " + getTokenName() + ": " + value, context);
} else if (bRemove) {
Type type = Type.getConstant(aType);
context.getObjectContext().removeFromList(head, ListKey.TYPE, type);
bRemove = false;
} else {
Type type = Type.getConstant(aType);
context.getObjectContext().addToList(head, ListKey.TYPE, type);
bAdd = false;
}
}
if (bRemove) {
return new ParseResult.Fail(getTokenName() + "ended with REMOVE, so didn't have any Type to remove: " + value, context);
}
if (bAdd) {
return new ParseResult.Fail(getTokenName() + "ended with ADD, so didn't have any Type to add: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations