Search in sources :

Example 1 with ParsingSeparator

use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.

the class TableLoader method generateCSVSeparator.

/**
	 * Generates a new "naive" CSV separator. This is not formally CSV compliant
	 * because it ignores "embedded" new lines. For purposes of PCGen this is
	 * acceptable.
	 * 
	 * @param lstLine
	 *            The line to be processed by a CSV-like ParsingSeparator
	 * @return A ParsingSeparator for the given line
	 */
private static ParsingSeparator generateCSVSeparator(String lstLine) {
    ParsingSeparator ps = new ParsingSeparator(lstLine, ',');
    ps.addGroupingPair('"', '"');
    return ps;
}
Also used : ParsingSeparator(pcgen.base.text.ParsingSeparator)

Example 2 with ParsingSeparator

use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.

the class ChoiceSetLoadUtilities method getChoiceSet.

public static <T extends CDOMObject> PrimitiveCollection<T> getChoiceSet(LoadContext context, SelectionCreator<T> sc, String joinedOr) {
    List<PrimitiveCollection<T>> orList = new ArrayList<>();
    ParsingSeparator pipe = new ParsingSeparator(joinedOr, '|');
    pipe.addGroupingPair('[', ']');
    pipe.addGroupingPair('(', ')');
    for (; pipe.hasNext(); ) {
        String joinedAnd = pipe.next();
        if (hasIllegalSeparator(',', joinedAnd)) {
            return null;
        }
        List<PrimitiveCollection<T>> andList = new ArrayList<>();
        ParsingSeparator comma = new ParsingSeparator(joinedAnd, ',');
        comma.addGroupingPair('[', ']');
        comma.addGroupingPair('(', ')');
        for (; comma.hasNext(); ) {
            String primitive = comma.next();
            if (primitive == null || primitive.isEmpty()) {
                Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was null or empty: " + primitive);
                return null;
            }
            QualifierToken<T> qual = getQualifier(context, sc, primitive);
            if (qual == null) {
                PrimitiveCollection<T> pcf = getSimplePrimitive(context, sc, primitive);
                if (pcf == null) {
                    Logging.addParseMessage(Logging.LST_ERROR, "Choice argument was not valid: " + primitive);
                    return null;
                } else {
                    andList.add(pcf);
                }
            } else {
                andList.add(qual);
            }
        }
        if (!andList.isEmpty()) {
            if (andList.size() == 1) {
                orList.add(andList.get(0));
            } else {
                orList.add(new CompoundAndPrimitive<>(andList));
            }
        }
    }
    if (orList.isEmpty()) {
        return null;
    } else if (orList.size() == 1) {
        return orList.get(0);
    } else {
        return new CompoundOrPrimitive<>(orList);
    }
}
Also used : ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) PrimitiveCollection(pcgen.cdom.base.PrimitiveCollection)

Example 3 with ParsingSeparator

use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.

the class ValuesToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitTable kitTable, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    while (sep.hasNext()) {
        String thing = sep.next();
        if (thing.isEmpty()) {
            return new ParseResult.Fail(getTokenName() + " arguments has invalid pipe separator: " + value, context);
        }
        KitGear optionInfo = new KitGear();
        for (String s : thing.split("[\\[\\]]")) {
            if (s.isEmpty()) {
                continue;
            }
            int colonLoc = s.indexOf(':');
            if (colonLoc == -1) {
                return new ParseResult.Fail("Expected colon in Value item: " + s + " within: " + value, context);
            }
            String key = s.substring(0, colonLoc);
            String thingValue = s.substring(colonLoc + 1);
            try {
                boolean passed = context.processToken(optionInfo, key, thingValue);
                if (!passed) {
                    return new ParseResult.Fail("Failure in token: " + key, context);
                }
            } catch (PersistenceLayerException e) {
                return new ParseResult.Fail("Failure in token: " + key + " " + e.getMessage(), context);
            }
        }
        if (!sep.hasNext()) {
            return new ParseResult.Fail("Odd token count in Value: " + value, context);
        }
        String range = sep.next();
        if (!processRange(kitTable, optionInfo, range)) {
            return new ParseResult.Fail("Invalid Range in Value: " + range + " within " + value, context);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) KitGear(pcgen.core.kit.KitGear) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 4 with ParsingSeparator

use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.

the class EquipBuyToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    if (looksLikeAPrerequisite(activeValue)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
    }
    Formula f = FormulaFactory.getFormulaFor(activeValue);
    if (!f.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
    }
    List<Prerequisite> prereqs = new ArrayList<>();
    while (sep.hasNext()) {
        activeValue = sep.next();
        Prerequisite prereq = getPrerequisite(activeValue);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        prereqs.add(prereq);
    }
    kit.put(ObjectKey.EQUIP_BUY, new QualifiedObject<>(f, prereqs));
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 5 with ParsingSeparator

use of pcgen.base.text.ParsingSeparator in project pcgen by PCGen.

the class TotalCostToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    if (looksLikeAPrerequisite(activeValue)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
    }
    Formula f = FormulaFactory.getFormulaFor(activeValue);
    if (!f.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
    }
    List<Prerequisite> prereqs = new ArrayList<>();
    while (sep.hasNext()) {
        activeValue = sep.next();
        Prerequisite prereq = getPrerequisite(activeValue);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put total costs after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        prereqs.add(prereq);
    }
    kit.put(ObjectKey.KIT_TOTAL_COST, new QualifiedObject<>(f, prereqs));
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

ParsingSeparator (pcgen.base.text.ParsingSeparator)35 Formula (pcgen.base.formula.Formula)26 ParseResult (pcgen.rules.persistence.token.ParseResult)18 ArrayList (java.util.ArrayList)15 CDOMReference (pcgen.cdom.base.CDOMReference)10 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)9 StringTokenizer (java.util.StringTokenizer)8 ChoiceSet (pcgen.cdom.base.ChoiceSet)7 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)6 PCClass (pcgen.core.PCClass)5 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)5 Ungranted (pcgen.cdom.base.Ungranted)4 Prerequisite (pcgen.core.prereq.Prerequisite)4 Skill (pcgen.core.Skill)3 LegalScope (pcgen.base.formula.base.LegalScope)2 PrimitiveCollection (pcgen.cdom.base.PrimitiveCollection)2 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)2 CNAbility (pcgen.cdom.content.CNAbility)2 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)2 Nature (pcgen.cdom.enumeration.Nature)2