Search in sources :

Example 16 with SpelNodeImpl

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;
}
Also used : OpInc(org.springframework.expression.spel.ast.OpInc) SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) OperatorPower(org.springframework.expression.spel.ast.OperatorPower) OpDec(org.springframework.expression.spel.ast.OpDec)

Example 17 with SpelNodeImpl

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;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Ternary(org.springframework.expression.spel.ast.Ternary) Elvis(org.springframework.expression.spel.ast.Elvis) Assign(org.springframework.expression.spel.ast.Assign) NullLiteral(org.springframework.expression.spel.ast.NullLiteral)

Example 18 with SpelNodeImpl

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;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Indexer(org.springframework.expression.spel.ast.Indexer)

Example 19 with SpelNodeImpl

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;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) VariableReference(org.springframework.expression.spel.ast.VariableReference) FunctionReference(org.springframework.expression.spel.ast.FunctionReference)

Example 20 with SpelNodeImpl

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;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) OpAnd(org.springframework.expression.spel.ast.OpAnd)

Aggregations

SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)21 ArrayList (java.util.ArrayList)3 PropertyOrFieldReference (org.springframework.expression.spel.ast.PropertyOrFieldReference)3 LinkedList (java.util.LinkedList)2 OpDec (org.springframework.expression.spel.ast.OpDec)2 OpInc (org.springframework.expression.spel.ast.OpInc)2 OpMinus (org.springframework.expression.spel.ast.OpMinus)2 OpPlus (org.springframework.expression.spel.ast.OpPlus)2 List (java.util.List)1 InternalParseException (org.springframework.expression.spel.InternalParseException)1 SpelParseException (org.springframework.expression.spel.SpelParseException)1 Assign (org.springframework.expression.spel.ast.Assign)1 CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)1 ConstructorReference (org.springframework.expression.spel.ast.ConstructorReference)1 Elvis (org.springframework.expression.spel.ast.Elvis)1 FunctionReference (org.springframework.expression.spel.ast.FunctionReference)1 Identifier (org.springframework.expression.spel.ast.Identifier)1 Indexer (org.springframework.expression.spel.ast.Indexer)1 InlineList (org.springframework.expression.spel.ast.InlineList)1 InlineMap (org.springframework.expression.spel.ast.InlineMap)1