Search in sources :

Example 6 with ComplexParseResult

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

the class LevelToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate template, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.COLON);
    String levelStr = tok.nextToken();
    int plusLoc = levelStr.indexOf('+');
    if (plusLoc == 0) {
        return new ParseResult.Fail("Malformed " + getTokenName() + " Level cannot start with +: " + value, context);
    }
    int lvl;
    try {
        /*
			 * Note this test of integer (even if it doesn't get used outside
			 * this try) is necessary for catching errors.
			 */
        lvl = Integer.parseInt(levelStr);
        if (lvl <= 0) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Malformed " + getTokenName() + " Token (Level was <= 0): " + lvl);
            cpr.addErrorMessage("  Line was: " + value);
            return cpr;
        }
    } catch (NumberFormatException ex) {
        return new ParseResult.Fail("Misunderstood Level value: " + levelStr + " in " + getTokenName(), context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has one): " + value, context);
    }
    String typeStr = tok.nextToken();
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has two): " + value, context);
    }
    String argument = tok.nextToken();
    PCTemplate derivative = new PCTemplate();
    derivative.put(ObjectKey.VISIBILITY, Visibility.HIDDEN);
    derivative.put(IntegerKey.LEVEL, lvl);
    context.getReferenceContext().getManufacturer(PCTemplate.class).addDerivativeObject(derivative);
    context.getObjectContext().addToList(template, ListKey.LEVEL_TEMPLATES, derivative);
    try {
        if (context.processToken(derivative, typeStr, argument)) {
            return ParseResult.SUCCESS;
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail(e.getMessage(), context);
    }
    return ParseResult.INTERNAL_ERROR;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCTemplate(pcgen.core.PCTemplate)

Example 7 with ComplexParseResult

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

the class ForwardRefToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Campaign obj, String value) {
    int pipeLoc = value.indexOf('|');
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " requires at least two arguments, " + "ReferenceType and Key: " + value, context);
    }
    if (value.lastIndexOf('|') != pipeLoc) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(getTokenName() + " requires at only two pipe separated arguments, " + "ReferenceType and Keys: " + value);
        cpr.addErrorMessage("  keys are comma separated");
        return cpr;
    }
    String firstToken = value.substring(0, pipeLoc);
    ReferenceManufacturer<? extends Loadable> rm = context.getManufacturer(firstToken);
    if (rm == null) {
        return new ParseResult.Fail(getTokenName() + " unable to generate manufacturer for type: " + value, context);
    }
    String rest = value.substring(pipeLoc + 1);
    if (hasIllegalSeparator(',', rest)) {
        return new ParseResult.Fail(getTokenName() + " keys are comma separated", context);
    }
    StringTokenizer st = new StringTokenizer(rest, Constants.COMMA);
    while (st.hasMoreTokens()) {
        CDOMSingleRef<? extends Loadable> ref = rm.getReference(st.nextToken());
        context.getObjectContext().addToList(obj, ListKey.FORWARDREF, new Qualifier(rm.getReferenceClass(), ref));
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Qualifier(pcgen.cdom.reference.Qualifier) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 8 with ComplexParseResult

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

the class ChooseFeatToken method parseTokenWithSeparator.

protected ParseResult parseTokenWithSeparator(LoadContext context, ReferenceManufacturer<Ability> rm, CDOMObject obj, String value) {
    int pipeLoc = value.lastIndexOf('|');
    String activeValue;
    String title;
    if (pipeLoc == -1) {
        activeValue = value;
        title = getDefaultTitle();
    } else {
        String titleString = value.substring(pipeLoc + 1);
        if (titleString.startsWith("TITLE=")) {
            title = titleString.substring(6);
            if (title.startsWith("\"")) {
                title = title.substring(1, title.length() - 1);
            }
            activeValue = value.substring(0, pipeLoc);
            if (title == null || title.isEmpty()) {
                return new ParseResult.Fail(getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value, context);
            }
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    PrimitiveCollection<Ability> coll = context.getChoiceSet(rm, activeValue);
    if (coll == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    if (!coll.getGroupingState().isValid()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Invalid combination of objects was used in: " + activeValue);
        cpr.addErrorMessage("  Check that ALL is not combined");
        cpr.addErrorMessage("  Check that a key is not joined with AND (,)");
        return cpr;
    }
    PrimitiveChoiceSet<Ability> pcs = new CollectionToChoiceSet<>(coll);
    //Tricky for compatibility...
    CategorizedChooseInformation<Ability> tc = new CategorizedChooseInformation<>("ABILITY", CDOMDirectSingleRef.getRef(AbilityCategory.FEAT), pcs, Ability.class);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CategorizedChooseInformation(pcgen.cdom.base.CategorizedChooseInformation) CollectionToChoiceSet(pcgen.cdom.choiceset.CollectionToChoiceSet) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 9 with ComplexParseResult

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

the class AbilityToken method parseTokenWithSeparator.

protected ParseResult parseTokenWithSeparator(LoadContext context, ReferenceManufacturer<Ability> rm, CDOMSingleRef<AbilityCategory> acRef, CDOMObject obj, String value) {
    int pipeLoc = value.lastIndexOf('|');
    String activeValue;
    String title;
    if (pipeLoc == -1) {
        activeValue = value;
        title = getDefaultTitle();
    } else {
        String titleString = value.substring(pipeLoc + 1);
        if (titleString.startsWith("TITLE=")) {
            title = titleString.substring(6);
            if (title.startsWith("\"")) {
                title = title.substring(1, title.length() - 1);
            }
            activeValue = value.substring(0, pipeLoc);
            if (title == null || title.isEmpty()) {
                return new ParseResult.Fail(getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value, context);
            }
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    PrimitiveCollection<Ability> coll = context.getChoiceSet(rm, activeValue);
    if (coll == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    if (!coll.getGroupingState().isValid()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Invalid combination of objects was used in: " + activeValue);
        cpr.addErrorMessage("  Check that ALL is not combined");
        cpr.addErrorMessage("  Check that a key is not joined with AND (,)");
        return cpr;
    }
    PrimitiveChoiceSet<Ability> pcs = new CollectionToChoiceSet<>(coll);
    CategorizedChooseInformation<Ability> tc = new CategorizedChooseInformation<>(getTokenName(), acRef, pcs, Ability.class);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CategorizedChooseInformation(pcgen.cdom.base.CategorizedChooseInformation) CollectionToChoiceSet(pcgen.cdom.choiceset.CollectionToChoiceSet) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 10 with ComplexParseResult

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

the class VisibleToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, 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 {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Unexpected value used in " + getTokenName() + " in Equipment");
        cpr.addErrorMessage(" " + value + " is not a valid value for " + getTokenName());
        cpr.addErrorMessage(" Valid values in Equipment are YES, NO, DISPLAY, EXPORT");
        return cpr;
    }
    context.getObjectContext().put(eq, ObjectKey.VISIBILITY, vis);
    return ParseResult.SUCCESS;
}
Also used : Visibility(pcgen.util.enumeration.Visibility) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Aggregations

ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)25 ParseResult (pcgen.rules.persistence.token.ParseResult)12 StringTokenizer (java.util.StringTokenizer)11 Ungranted (pcgen.cdom.base.Ungranted)6 PCClass (pcgen.core.PCClass)5 ArrayList (java.util.ArrayList)4 Ability (pcgen.core.Ability)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AddingFormula (pcgen.base.formula.AddingFormula)2 DividingFormula (pcgen.base.formula.DividingFormula)2 Formula (pcgen.base.formula.Formula)2 MultiplyingFormula (pcgen.base.formula.MultiplyingFormula)2 SubtractingFormula (pcgen.base.formula.SubtractingFormula)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 CategorizedChooseInformation (pcgen.cdom.base.CategorizedChooseInformation)2 CollectionToChoiceSet (pcgen.cdom.choiceset.CollectionToChoiceSet)2 HitDie (pcgen.cdom.content.HitDie)2 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)2 PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 HitDieFormula (pcgen.cdom.processor.HitDieFormula)2