Search in sources :

Example 1 with FormatManager

use of pcgen.base.util.FormatManager in project pcgen by PCGen.

the class DropIntoContext method allowFromScopeName.

private FormatManager<?> allowFromScopeName(SemanticsVisitor visitor, FormulaSemantics semantics, String legalScopeName, Node node) {
    FormulaManager fm = semantics.get(FormulaSemantics.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    LegalScope legalScope = siFactory.getScope(legalScopeName);
    if (legalScope == null) {
        semantics.setInvalid("Parse Error: Invalid Scope Name: " + legalScopeName + " is not a valid scope name");
        return null;
    }
    //Rest of Equation
    semantics = semantics.getWith(FormulaSemantics.FMANAGER, fm);
    semantics = semantics.getWith(FormulaSemantics.SCOPE, legalScope);
    FormatManager<?> format = (FormatManager<?>) node.jjtAccept(visitor, semantics);
    return format;
}
Also used : FormulaManager(pcgen.base.formula.base.FormulaManager) LegalScope(pcgen.base.formula.base.LegalScope) FormatManager(pcgen.base.util.FormatManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 2 with FormatManager

use of pcgen.base.util.FormatManager in project pcgen by PCGen.

the class DropIntoContext method allowThreeArguments.

private FormatManager<?> allowThreeArguments(SemanticsVisitor visitor, FormulaSemantics semantics, Node[] args) {
    Node scopeNode = args[0];
    if (!(scopeNode instanceof ASTQuotString)) {
        semantics.setInvalid("Parse Error: Invalid Scope Node: " + scopeNode.getClass().getName() + " found in location requiring a" + " Static String (first arg cannot be evaluated)");
        return null;
    }
    ASTQuotString qs = (ASTQuotString) scopeNode;
    String legalScopeName = qs.getText();
    if (args[1] instanceof ASTQuotString) {
        //Direct,  no dependencies
        return allowFromScopeName(visitor, semantics, legalScopeName, args[2]);
    } else if (args[1] instanceof ASTPCGenSingleWord) {
        //Variable
        semantics = semantics.getWith(FormulaSemantics.ASSERTED, null);
        FormatManager<?> objClass = (FormatManager<?>) args[1].jjtAccept(visitor, semantics);
        if (!semantics.isValid()) {
            return null;
        }
        Class<?> managedClass = objClass.getManagedClass();
        if (String.class.isAssignableFrom(managedClass) || VarScoped.class.isAssignableFrom(objClass.getManagedClass())) {
            return allowFromScopeName(visitor, semantics, legalScopeName, args[2]);
        } else {
            semantics.setInvalid("Parse Error: Invalid Object Format: " + objClass + " is not capable of holding variables and is not a key (String)");
            return null;
        }
    } else {
        //Error
        semantics.setInvalid("Parse Error: Invalid second argument: " + " must be a String or single variable");
        return null;
    }
}
Also used : Node(pcgen.base.formula.parse.Node) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) FormatManager(pcgen.base.util.FormatManager) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) ASTPCGenSingleWord(pcgen.base.formula.parse.ASTPCGenSingleWord)

Example 3 with FormatManager

use of pcgen.base.util.FormatManager in project pcgen by PCGen.

the class FaceToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier " + MOD_IDENTIFICATION + " had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    if (!context.getVariableContext().isLegalVariableID(scope, VAR_NAME)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid var name: " + VAR_NAME + ", Modified on " + race.getClass().getSimpleName() + ' ' + race.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(VAR_NAME, scope, modifier);
    context.getObjectContext().addToList(race, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) OrderedPair(pcgen.base.math.OrderedPair) FormatManager(pcgen.base.util.FormatManager)

Example 4 with FormatManager

use of pcgen.base.util.FormatManager in project pcgen by PCGen.

the class FaceToken method parseFace.

protected ParseResult parseFace(LoadContext context, PCTemplate fObj, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    @SuppressWarnings("unchecked") FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier SET had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    String varName = VAR_NAME;
    if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid fact name: " + varName + ", Modified on " + fObj.getClass().getSimpleName() + ' ' + fObj.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(varName, scope, modifier);
    context.getObjectContext().addToList(fObj, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) OrderedPair(pcgen.base.math.OrderedPair) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) FormatManager(pcgen.base.util.FormatManager)

Aggregations

FormatManager (pcgen.base.util.FormatManager)4 LegalScope (pcgen.base.formula.base.LegalScope)3 ScopeInstance (pcgen.base.formula.base.ScopeInstance)2 OrderedPair (pcgen.base.math.OrderedPair)2 VarModifier (pcgen.cdom.content.VarModifier)2 ParseResult (pcgen.rules.persistence.token.ParseResult)2 FormulaManager (pcgen.base.formula.base.FormulaManager)1 ScopeInstanceFactory (pcgen.base.formula.inst.ScopeInstanceFactory)1 ASTPCGenSingleWord (pcgen.base.formula.parse.ASTPCGenSingleWord)1 ASTQuotString (pcgen.base.formula.parse.ASTQuotString)1 Node (pcgen.base.formula.parse.Node)1