Search in sources :

Example 1 with Node

use of pcgen.base.formula.parse.Node 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 2 with Node

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

the class InputFunction method allowArgs.

@Override
public final FormatManager<?> allowArgs(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics) {
    int argCount = args.length;
    if (argCount != 1) {
        semantics.setInvalid("Function " + getFunctionName() + " received incorrect # of arguments, expected: 1 got " + args.length + ' ' + Arrays.asList(args));
        return null;
    }
    //String node (name)
    Node inputNode = args[0];
    if (inputNode.getId() != FormulaParserTreeConstants.JJTQUOTSTRING) {
        semantics.setInvalid("Parse Error: Invalid Value: " + ((SimpleNode) inputNode).getText() + " found in " + inputNode.getClass().getName() + " found in location requiring a literal" + " String (cannot be evaluated)");
        return null;
    }
    String inputName = ((SimpleNode) inputNode).getText();
    String varName = ChannelUtilities.createVarName(inputName);
    VariableLibrary varLib = semantics.get(FormulaSemantics.FMANAGER).getFactory();
    LegalScope scope = semantics.get(FormulaSemantics.SCOPE);
    FormatManager<?> formatManager = varLib.getVariableFormat(scope, varName);
    if (formatManager == null) {
        semantics.setInvalid("Input Channel: " + varName + " was not found");
        return null;
    }
    return formatManager;
}
Also used : LegalScope(pcgen.base.formula.base.LegalScope) SimpleNode(pcgen.base.formula.parse.SimpleNode) Node(pcgen.base.formula.parse.Node) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) SimpleNode(pcgen.base.formula.parse.SimpleNode) VariableLibrary(pcgen.base.formula.base.VariableLibrary)

Aggregations

ASTQuotString (pcgen.base.formula.parse.ASTQuotString)2 Node (pcgen.base.formula.parse.Node)2 LegalScope (pcgen.base.formula.base.LegalScope)1 VariableLibrary (pcgen.base.formula.base.VariableLibrary)1 ASTPCGenSingleWord (pcgen.base.formula.parse.ASTPCGenSingleWord)1 SimpleNode (pcgen.base.formula.parse.SimpleNode)1 FormatManager (pcgen.base.util.FormatManager)1