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;
}
}
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;
}
Aggregations