Search in sources :

Example 1 with KitGear

use of pcgen.core.kit.KitGear 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)

Aggregations

ParsingSeparator (pcgen.base.text.ParsingSeparator)1 KitGear (pcgen.core.kit.KitGear)1 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1