Search in sources :

Example 1 with OpMinus

use of org.springframework.expression.spel.ast.OpMinus in project spring-framework by spring-projects.

the class InternalSpelExpressionParser method eatSumExpression.

// sumExpression: productExpression ( (PLUS^ | MINUS^) productExpression)*;
@Nullable
private SpelNodeImpl eatSumExpression() {
    SpelNodeImpl expr = eatProductExpression();
    while (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.INC)) {
        // consume PLUS or MINUS or INC
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatProductExpression();
        checkRightOperand(t, rhExpr);
        if (t.kind == TokenKind.PLUS) {
            expr = new OpPlus(t.startPos, t.endPos, expr, rhExpr);
        } else if (t.kind == TokenKind.MINUS) {
            expr = new OpMinus(t.startPos, t.endPos, expr, rhExpr);
        }
    }
    return expr;
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) OpPlus(org.springframework.expression.spel.ast.OpPlus) OpMinus(org.springframework.expression.spel.ast.OpMinus) Nullable(org.springframework.lang.Nullable)

Example 2 with OpMinus

use of org.springframework.expression.spel.ast.OpMinus in project spring-framework by spring-projects.

the class InternalSpelExpressionParser method eatUnaryExpression.

// unaryExpression: (PLUS^ | MINUS^ | BANG^ | INC^ | DEC^) unaryExpression | primaryExpression ;
@Nullable
private SpelNodeImpl eatUnaryExpression() {
    if (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.NOT)) {
        Token t = takeToken();
        SpelNodeImpl expr = eatUnaryExpression();
        Assert.state(expr != null, "No node");
        if (t.kind == TokenKind.NOT) {
            return new OperatorNot(t.startPos, t.endPos, expr);
        }
        if (t.kind == TokenKind.PLUS) {
            return new OpPlus(t.startPos, t.endPos, expr);
        }
        Assert.isTrue(t.kind == TokenKind.MINUS, "Minus token expected");
        return new OpMinus(t.startPos, t.endPos, expr);
    }
    if (peekToken(TokenKind.INC, TokenKind.DEC)) {
        Token t = takeToken();
        SpelNodeImpl expr = eatUnaryExpression();
        if (t.getKind() == TokenKind.INC) {
            return new OpInc(t.startPos, t.endPos, false, expr);
        }
        return new OpDec(t.startPos, t.endPos, false, expr);
    }
    return eatPrimaryExpression();
}
Also used : OpInc(org.springframework.expression.spel.ast.OpInc) SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) OpPlus(org.springframework.expression.spel.ast.OpPlus) OperatorNot(org.springframework.expression.spel.ast.OperatorNot) OpMinus(org.springframework.expression.spel.ast.OpMinus) OpDec(org.springframework.expression.spel.ast.OpDec) Nullable(org.springframework.lang.Nullable)

Aggregations

OpMinus (org.springframework.expression.spel.ast.OpMinus)2 OpPlus (org.springframework.expression.spel.ast.OpPlus)2 SpelNodeImpl (org.springframework.expression.spel.ast.SpelNodeImpl)2 Nullable (org.springframework.lang.Nullable)2 OpDec (org.springframework.expression.spel.ast.OpDec)1 OpInc (org.springframework.expression.spel.ast.OpInc)1 OperatorNot (org.springframework.expression.spel.ast.OperatorNot)1