use of org.cytoscape.equations.internal.parse_tree.FuncCallNode in project cytoscape-impl by cytoscape.
the class EquationParserImpl method parseFunctionCall.
/**
* Implements func_call --> ident "(" ")" | ident "(" expr {"," expr} ")".
*/
private AbstractNode parseFunctionCall() {
Token token = tokeniser.getToken();
final int functionNameStartPos = tokeniser.getStartPos();
if (token != Token.IDENTIFIER)
throw new IllegalStateException(functionNameStartPos + ": function name expected.");
final String originalName = tokeniser.getIdent();
final String functionNameCandidate = originalName.toUpperCase();
if (functionNameCandidate.equals("DEFINED"))
return parseDefined();
final Function func = nameToFunctionMap.get(functionNameCandidate);
if (func == null) {
if (tokeniser.getToken() == Token.OPEN_PAREN)
throw new IllegalStateException(functionNameStartPos + ": call to unknown function " + originalName + "().");
else
throw new IllegalStateException(functionNameStartPos + ": unknown text \"" + originalName + "\", maybe you forgot to put quotes around this text?");
}
token = tokeniser.getToken();
final int openParenPos = tokeniser.getStartPos();
if (token != Token.OPEN_PAREN)
throw new IllegalStateException(openParenPos + ": expected '(' after function name \"" + functionNameCandidate + "\".");
// Parse the comma-separated argument list.
final ArrayList<Class<?>> argTypes = new ArrayList<Class<?>>();
ArrayList<AbstractNode> args = new ArrayList<AbstractNode>();
int sourceLocation;
for (; ; ) {
token = tokeniser.getToken();
sourceLocation = tokeniser.getStartPos();
if (token == Token.CLOSE_PAREN)
break;
tokeniser.ungetToken(token);
final AbstractNode exprNode = parseExpr();
argTypes.add(exprNode.getType());
args.add(exprNode);
token = tokeniser.getToken();
sourceLocation = tokeniser.getStartPos();
if (token != Token.COMMA)
break;
}
final Class<?> returnType = func.validateArgTypes(argTypes.toArray(new Class<?>[argTypes.size()]));
if (returnType == null)
throw new IllegalStateException((openParenPos + 1) + ": invalid number or type of arguments in call to " + functionNameCandidate + "().");
if (token != Token.CLOSE_PAREN)
throw new IllegalStateException(sourceLocation + ": expected the closing parenthesis of a call to " + functionNameCandidate + ".");
AbstractNode[] nodeArray = new AbstractNode[args.size()];
return new FuncCallNode(functionNameStartPos, func, returnType, args.toArray(nodeArray));
}
Aggregations