use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.
the class JDOQLParser method processArray.
/**
* Method to parse an array expression ("{a,b,c}"), creating an ARRAY node with the node value
* being a List<Node> of the elements. Also handles processing of subsequent "length" 'method'
* which is special case for arrays and not caught by processMethod() since it doesn't have "()".
* @return Whether an array was parsed from the current position
*/
private boolean processArray() {
if (lexer.parseChar('{')) {
// Array
List<Node> elements = new ArrayList();
while (!lexer.parseChar('}')) {
processPrimary();
Node elementNode = stack.pop();
elements.add(elementNode);
if (lexer.parseChar('}')) {
break;
} else if (!lexer.parseChar(',')) {
throw new QueryCompilerSyntaxException("',' or '}' expected", lexer.getIndex(), lexer.getInput());
}
}
Node arrayNode = new Node(NodeType.ARRAY, elements);
stack.push(arrayNode);
// Check for "length" since won't be picked up by processMethod
if (lexer.parseString(".length")) {
Node lengthMethod = new Node(NodeType.INVOKE, "length");
arrayNode.appendChildNode(lengthMethod);
}
return true;
}
return false;
}
use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.
the class JDOQLParser method processUnaryExpression.
protected void processUnaryExpression() {
if (lexer.parseString("++")) {
throw new QueryCompilerSyntaxException("Unsupported operator '++'");
} else if (lexer.parseString("--")) {
throw new QueryCompilerSyntaxException("Unsupported operator '--'");
}
if (lexer.parseChar('+')) {
// Just swallow + and leave remains on the stack
processUnaryExpression();
} else if (lexer.parseChar('-')) {
processUnaryExpression();
Node expr = new Node(NodeType.OPERATOR, "-");
expr.insertChildNode(stack.pop());
stack.push(expr);
} else if (lexer.parseChar('~')) {
processUnaryExpression();
Node expr = new Node(NodeType.OPERATOR, "~");
expr.insertChildNode(stack.pop());
stack.push(expr);
} else if (lexer.parseChar('!')) {
processUnaryExpression();
Node expr = new Node(NodeType.OPERATOR, "!");
expr.insertChildNode(stack.pop());
stack.push(expr);
} else {
processPrimary();
}
}
use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.
the class JDOQLParser method parseParameters.
/* (non-Javadoc)
* @see org.datanucleus.query.compiler.Parser#parseParameters(java.lang.String)
*/
public Node[][] parseParameters(String expression) {
List nodes = new ArrayList();
StringTokenizer tokeniser = new StringTokenizer(expression, ",");
while (tokeniser.hasMoreTokens()) {
String token = tokeniser.nextToken();
StringTokenizer subTokeniser = new StringTokenizer(token, " ");
if (subTokeniser.countTokens() != 2) {
throw new QueryCompilerSyntaxException(Localiser.msg("021101", expression));
}
String classDecl = subTokeniser.nextToken();
String parameterName = subTokeniser.nextToken();
Node declNode = new Node(NodeType.IDENTIFIER, classDecl);
Node nameNode = new Node(NodeType.IDENTIFIER, parameterName);
nodes.add(new Node[] { declNode, nameNode });
}
return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
}
use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.
the class JDOQLParser method processCreator.
/**
* Method to parse "new a.b.c(param1[,param2], ...)" and create a Node of type CREATOR.
* The Node at the top of the stack after this call will have any arguments defined in its "properties".
* @return whether method syntax was found.
*/
private boolean processCreator() {
if (lexer.parseString("new ")) {
int size = stack.size();
if (!processMethod()) {
if (!processIdentifier()) {
throw new QueryCompilerSyntaxException("Identifier expected", lexer.getIndex(), lexer.getInput());
}
while (lexer.parseChar('.')) {
if (processMethod()) {
// "a.method(...)"
} else if (processIdentifier()) {
// "a.field"
} else {
throw new QueryCompilerSyntaxException("Identifier expected", lexer.getIndex(), lexer.getInput());
}
}
}
while (stack.size() - 1 > size) {
Node top = stack.pop();
Node peek = stack.peek();
peek.insertChildNode(top);
}
Node expr = stack.pop();
Node newExpr = new Node(NodeType.CREATOR);
newExpr.insertChildNode(expr);
stack.push(newExpr);
return true;
}
return false;
}
use of org.datanucleus.store.query.QueryCompilerSyntaxException in project datanucleus-core by datanucleus.
the class JPQLParser method parseParameters.
/* (non-Javadoc)
* @see org.datanucleus.query.compiler.Parser#parseParameters(java.lang.String)
*/
public Node[][] parseParameters(String expression) {
lexer = new Lexer(expression, paramPrefixes, false);
List nodes = new ArrayList();
do {
processPrimary();
if (stack.isEmpty()) {
throw new QueryCompilerSyntaxException("expected identifier", lexer.getIndex(), lexer.getInput());
}
if (!processIdentifier()) {
throw new QueryCompilerSyntaxException("expected identifier", lexer.getIndex(), lexer.getInput());
}
Node nodeVariable = stack.pop();
Node nodeType = stack.pop();
nodes.add(new Node[] { nodeType, nodeVariable });
} while (lexer.parseString(","));
return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
}
Aggregations