Search in sources :

Example 41 with ParseResult

use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.

the class GlobalMoveTest method processToken.

@Override
public void processToken(CDOMObject source) {
    ParseResult result = token.parseToken(context, source, "Fly,30");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    finishLoad();
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 42 with ParseResult

use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.

the class GlobalQualifyTest method testFromEqMod.

@Override
@Test
public void testFromEqMod() throws PersistenceLayerException {
    EquipmentModifier source = create(EquipmentModifier.class, "Source");
    ParseResult result = token.parseToken(context, source, "RACE|Dwarf");
    assertFalse(result.passed());
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test) AbstractContentTokenTest(tokencontent.testsupport.AbstractContentTokenTest)

Example 43 with ParseResult

use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.

the class ExchangelevelToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    final StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    if (tok.countTokens() != 4) {
        return new ParseResult.Fail(getTokenName() + " must have 4 | delimited arguments : " + value, context);
    }
    String classString = tok.nextToken();
    CDOMSingleRef<PCClass> cl = context.getReferenceContext().getCDOMReference(PCClass.class, classString);
    String mindlString = tok.nextToken();
    int mindl;
    try {
        mindl = Integer.parseInt(mindlString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + mindlString, context);
    }
    String maxdlString = tok.nextToken();
    int maxdl;
    try {
        maxdl = Integer.parseInt(maxdlString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + maxdlString, context);
    }
    String minremString = tok.nextToken();
    int minrem;
    try {
        minrem = Integer.parseInt(minremString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + minremString, context);
    }
    try {
        LevelExchange le = new LevelExchange(cl, mindl, maxdl, minrem);
        context.getObjectContext().put(pcc, ObjectKey.EXCHANGE_LEVEL, le);
        return ParseResult.SUCCESS;
    } catch (IllegalArgumentException e) {
        ComplexParseResult pr = new ComplexParseResult();
        pr.addErrorMessage("Error in " + getTokenName() + ' ' + e.getMessage());
        pr.addErrorMessage("  Token contents: " + value);
        return pr;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) LevelExchange(pcgen.cdom.content.LevelExchange) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass)

Example 44 with ParseResult

use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.

the class RankToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitSkill kitSkill, String value) {
    try {
        BigDecimal rank = new BigDecimal(value);
        if (rank.compareTo(BigDecimal.ZERO) < 0) {
            return new ParseResult.Fail(getTokenName() + " must be a positive number: " + value, context);
        }
        kitSkill.setRank(rank);
        return ParseResult.SUCCESS;
    } catch (NumberFormatException e) {
        return new ParseResult.Fail(getTokenName() + " expected a number: " + value, context);
    }
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) BigDecimal(java.math.BigDecimal)

Example 45 with ParseResult

use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.

the class ApplyToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
    try {
        KitApply ka = KitApply.valueOf(value);
        kit.put(ObjectKey.APPLY_MODE, ka);
        return ParseResult.SUCCESS;
    } catch (IllegalArgumentException e) {
        return new ParseResult.Fail(getTokenName() + " encountered unexpected application type: " + value, context);
    }
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) KitApply(pcgen.cdom.enumeration.KitApply)

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