Search in sources :

Example 81 with ParseResult

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;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 82 with ParseResult

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;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 83 with ParseResult

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

Example 84 with ParseResult

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

Example 85 with ParseResult

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

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