use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatPowerIncDecExpression.
// powerExpr : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
private SpelNodeImpl eatPowerIncDecExpression() {
SpelNodeImpl expr = eatUnaryExpression();
if (peekToken(TokenKind.POWER)) {
//consume POWER
Token t = nextToken();
SpelNodeImpl rhExpr = eatUnaryExpression();
checkRightOperand(t, rhExpr);
return new OperatorPower(toPos(t), expr, rhExpr);
}
if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
//consume INC/DEC
Token t = nextToken();
if (t.getKind() == TokenKind.INC) {
return new OpInc(toPos(t), true, expr);
}
return new OpDec(toPos(t), true, expr);
}
return expr;
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatExpression.
// expression
// : logicalOrExpression
// ( (ASSIGN^ logicalOrExpression)
// | (DEFAULT^ logicalOrExpression)
// | (QMARK^ expression COLON! expression)
// | (ELVIS^ expression))?;
private SpelNodeImpl eatExpression() {
SpelNodeImpl expr = eatLogicalOrExpression();
if (moreTokens()) {
Token t = peekToken();
if (t.kind == TokenKind.ASSIGN) {
// a=b
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
}
nextToken();
SpelNodeImpl assignedValue = eatLogicalOrExpression();
return new Assign(toPos(t), expr, assignedValue);
}
if (t.kind == TokenKind.ELVIS) {
// a?:b (a if it isn't null, otherwise b)
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 2));
}
// elvis has left the building
nextToken();
SpelNodeImpl valueIfNull = eatExpression();
if (valueIfNull == null) {
valueIfNull = new NullLiteral(toPos(t.startPos + 1, t.endPos + 1));
}
return new Elvis(toPos(t), expr, valueIfNull);
}
if (t.kind == TokenKind.QMARK) {
// a?b:c
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
}
nextToken();
SpelNodeImpl ifTrueExprValue = eatExpression();
eatToken(TokenKind.COLON);
SpelNodeImpl ifFalseExprValue = eatExpression();
return new Ternary(toPos(t), expr, ifTrueExprValue, ifFalseExprValue);
}
}
return expr;
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method maybeEatIndexer.
private boolean maybeEatIndexer() {
Token t = peekToken();
if (!peekToken(TokenKind.LSQUARE, true)) {
return false;
}
SpelNodeImpl expr = eatExpression();
eatToken(TokenKind.RSQUARE);
this.constructedNodes.push(new Indexer(toPos(t), expr));
return true;
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method maybeEatFunctionOrVar.
// functionOrVar
// : (POUND ID LPAREN) => function
// | var
//
// function : POUND id=ID methodArgs -> ^(FUNCTIONREF[$id] methodArgs);
// var : POUND id=ID -> ^(VARIABLEREF[$id]);
private boolean maybeEatFunctionOrVar() {
if (!peekToken(TokenKind.HASH)) {
return false;
}
Token t = nextToken();
Token functionOrVariableName = eatToken(TokenKind.IDENTIFIER);
SpelNodeImpl[] args = maybeEatMethodArgs();
if (args == null) {
push(new VariableReference(functionOrVariableName.data, toPos(t.startPos, functionOrVariableName.endPos)));
return true;
}
push(new FunctionReference(functionOrVariableName.data, toPos(t.startPos, functionOrVariableName.endPos), args));
return true;
}
use of org.springframework.expression.spel.ast.SpelNodeImpl in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatLogicalAndExpression.
// logicalAndExpression : relationalExpression (AND^ relationalExpression)*;
private SpelNodeImpl eatLogicalAndExpression() {
SpelNodeImpl expr = eatRelationalExpression();
while (peekIdentifierToken("and") || peekToken(TokenKind.SYMBOLIC_AND)) {
// consume 'AND'
Token t = nextToken();
SpelNodeImpl rhExpr = eatRelationalExpression();
checkOperands(t, expr, rhExpr);
expr = new OpAnd(toPos(t), expr, rhExpr);
}
return expr;
}
Aggregations