use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method doParseExpression.
@Override
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
try {
this.expressionString = expressionString;
Tokenizer tokenizer = new Tokenizer(expressionString);
tokenizer.process();
this.tokenStream = tokenizer.getTokens();
this.tokenStreamLength = this.tokenStream.size();
this.tokenStreamPointer = 0;
this.constructedNodes.clear();
SpelNodeImpl ast = eatExpression();
if (moreTokens()) {
throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken()));
}
Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected");
return new SpelExpression(expressionString, ast, this.configuration);
} catch (InternalParseException ex) {
throw ex.getCause();
}
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method maybeEatParenExpression.
//parenExpr : LPAREN! expression RPAREN!;
private boolean maybeEatParenExpression() {
if (peekToken(TokenKind.LPAREN)) {
nextToken();
SpelNodeImpl expr = eatExpression();
eatToken(TokenKind.RPAREN);
push(expr);
return true;
} else {
return false;
}
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatUnaryExpression.
// unaryExpression: (PLUS^ | MINUS^ | BANG^ | INC^ | DEC^) unaryExpression | primaryExpression ;
private SpelNodeImpl eatUnaryExpression() {
if (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.NOT)) {
Token t = nextToken();
SpelNodeImpl expr = eatUnaryExpression();
if (t.kind == TokenKind.NOT) {
return new OperatorNot(toPos(t), expr);
}
if (t.kind == TokenKind.PLUS) {
return new OpPlus(toPos(t), expr);
}
Assert.isTrue(t.kind == TokenKind.MINUS, "Minus token expected");
return new OpMinus(toPos(t), expr);
}
if (peekToken(TokenKind.INC, TokenKind.DEC)) {
Token t = nextToken();
SpelNodeImpl expr = eatUnaryExpression();
if (t.getKind() == TokenKind.INC) {
return new OpInc(toPos(t), false, expr);
}
return new OpDec(toPos(t), false, expr);
}
return eatPrimaryExpression();
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatPossiblyQualifiedId.
/**
* Eat an identifier, possibly qualified (meaning that it is dotted).
* TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c)
*/
private SpelNodeImpl eatPossiblyQualifiedId() {
LinkedList<SpelNodeImpl> qualifiedIdPieces = new LinkedList<>();
Token node = peekToken();
while (isValidQualifiedId(node)) {
nextToken();
if (node.kind != TokenKind.DOT) {
qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node)));
}
node = peekToken();
}
if (qualifiedIdPieces.isEmpty()) {
if (node == null) {
raiseInternalException(this.expressionString.length(), SpelMessage.OOD);
}
raiseInternalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase());
}
int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition());
return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[qualifiedIdPieces.size()]));
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatPrimaryExpression.
// primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?);
private SpelNodeImpl eatPrimaryExpression() {
List<SpelNodeImpl> nodes = new ArrayList<>();
// always a start node
SpelNodeImpl start = eatStartNode();
nodes.add(start);
while (maybeEatNode()) {
nodes.add(pop());
}
if (nodes.size() == 1) {
return nodes.get(0);
}
return new CompoundExpression(toPos(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition()), nodes.toArray(new SpelNodeImpl[nodes.size()]));
}
Aggregations