Search in sources :

Example 86 with ParseResult

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();
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 87 with ParseResult

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();
}
Also used : DatasetVariable(pcgen.cdom.content.DatasetVariable) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test)

Example 88 with ParseResult

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();
}
Also used : DatasetVariable(pcgen.cdom.content.DatasetVariable) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test)

Example 89 with ParseResult

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();
}
Also used : DatasetVariable(pcgen.cdom.content.DatasetVariable) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test)

Example 90 with ParseResult

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;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) StringTokenizer(java.util.StringTokenizer) Type(pcgen.cdom.enumeration.Type) ParseResult(pcgen.rules.persistence.token.ParseResult)

Aggregations

ParseResult (pcgen.rules.persistence.token.ParseResult)210 StringTokenizer (java.util.StringTokenizer)68 Test (org.junit.Test)45 CDOMReference (pcgen.cdom.base.CDOMReference)30 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)26 Ability (pcgen.core.Ability)21 ArrayList (java.util.ArrayList)18 Formula (pcgen.base.formula.Formula)18 ParsingSeparator (pcgen.base.text.ParsingSeparator)18 Prerequisite (pcgen.core.prereq.Prerequisite)18 PCClass (pcgen.core.PCClass)17 Ungranted (pcgen.cdom.base.Ungranted)15 PCTemplate (pcgen.core.PCTemplate)14 CNAbility (pcgen.cdom.content.CNAbility)13 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)11 BigDecimal (java.math.BigDecimal)10 Race (pcgen.core.Race)10 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)9 LegalScope (pcgen.base.formula.base.LegalScope)8