Search in sources :

Example 1 with ASTQuotString

use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.

the class DropIntoContext method evaluate.

@Override
public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) {
    ASTQuotString qs = (ASTQuotString) args[0];
    String legalScopeName = qs.getText();
    Object result = args[1].jjtAccept(visitor, manager);
    VarScoped vs;
    if (result instanceof String) {
        Class<? extends Loadable> objClass = StringPClassUtil.getClassFor(legalScopeName);
        vs = (VarScoped) manager.get(ManagerKey.CONTEXT).getReferenceContext().silentlyGetConstructedCDOMObject(objClass, (String) result);
    } else if (result instanceof VarScoped) {
        vs = (VarScoped) result;
    } else {
        throw new IllegalStateException("result must be String or VarScoped");
    }
    return evaluateFromObject(visitor, legalScopeName, vs, args[2], manager);
}
Also used : ASTQuotString(pcgen.base.formula.parse.ASTQuotString) VarScoped(pcgen.base.formula.base.VarScoped) ASTQuotString(pcgen.base.formula.parse.ASTQuotString)

Example 2 with ASTQuotString

use of pcgen.base.formula.parse.ASTQuotString 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 ASTQuotString

use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.

the class DropIntoContext method getDependencies.

@Override
public void getDependencies(DependencyVisitor visitor, DependencyManager fdm, Node[] args) {
    String legalScopeName = ((ASTQuotString) args[0]).getText();
    TrainingStrategy ts = new TrainingStrategy();
    DependencyManager trainer = fdm.getWith(DependencyManager.VARSTRATEGY, ts);
    if (args[1] instanceof ASTQuotString) {
    //Direct,  no dependencies
    } else if (args[1] instanceof ASTPCGenSingleWord) {
        //Variable
        args[1].jjtAccept(visitor, trainer);
    } else {
    //Error
    }
    DynamicDependency dd = new DynamicDependency(ts.getControlVar(), legalScopeName);
    fdm.get(DependencyManager.DYNAMIC).addDependency(dd);
    DependencyManager dynamic = fdm.getWith(DependencyManager.VARSTRATEGY, dd);
    //Rest of Equation
    args[2].jjtAccept(visitor, dynamic);
}
Also used : DynamicDependency(pcgen.base.formula.base.DynamicDependency) TrainingStrategy(pcgen.base.formula.base.TrainingStrategy) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) DependencyManager(pcgen.base.formula.base.DependencyManager) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) ASTPCGenSingleWord(pcgen.base.formula.parse.ASTPCGenSingleWord)

Example 4 with ASTQuotString

use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.

the class InputFunction method getDependencies.

@Override
public void getDependencies(DependencyVisitor visitor, DependencyManager fdm, Node[] args) {
    ASTQuotString inputName = (ASTQuotString) args[0];
    String varName = inputName.getText();
    visitor.visitVariable(ChannelUtilities.createVarName(varName), fdm);
}
Also used : ASTQuotString(pcgen.base.formula.parse.ASTQuotString) ASTQuotString(pcgen.base.formula.parse.ASTQuotString)

Aggregations

ASTQuotString (pcgen.base.formula.parse.ASTQuotString)4 ASTPCGenSingleWord (pcgen.base.formula.parse.ASTPCGenSingleWord)2 DependencyManager (pcgen.base.formula.base.DependencyManager)1 DynamicDependency (pcgen.base.formula.base.DynamicDependency)1 TrainingStrategy (pcgen.base.formula.base.TrainingStrategy)1 VarScoped (pcgen.base.formula.base.VarScoped)1 Node (pcgen.base.formula.parse.Node)1 FormatManager (pcgen.base.util.FormatManager)1