Search in sources :

Example 1 with OpInc

use of cn.taketoday.expression.spel.ast.OpInc in project today-framework by TAKETODAY.

the class InternalSpelExpressionParser method eatPowerIncDecExpression.

// powerExpr  : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
@Nullable
private SpelNodeImpl eatPowerIncDecExpression() {
    SpelNodeImpl expr = eatUnaryExpression();
    if (peekToken(TokenKind.POWER)) {
        // consume POWER
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatUnaryExpression();
        checkRightOperand(t, rhExpr);
        return new OperatorPower(t.startPos, t.endPos, expr, rhExpr);
    }
    if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
        // consume INC/DEC
        Token t = takeToken();
        if (t.kind == TokenKind.INC) {
            return new OpInc(t.startPos, t.endPos, true, expr);
        }
        return new OpDec(t.startPos, t.endPos, true, expr);
    }
    return expr;
}
Also used : OpInc(cn.taketoday.expression.spel.ast.OpInc) SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorPower(cn.taketoday.expression.spel.ast.OperatorPower) OpDec(cn.taketoday.expression.spel.ast.OpDec) Nullable(cn.taketoday.lang.Nullable)

Example 2 with OpInc

use of cn.taketoday.expression.spel.ast.OpInc in project today-framework by TAKETODAY.

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.kind == 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(cn.taketoday.expression.spel.ast.OpInc) SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OpPlus(cn.taketoday.expression.spel.ast.OpPlus) OperatorNot(cn.taketoday.expression.spel.ast.OperatorNot) OpMinus(cn.taketoday.expression.spel.ast.OpMinus) OpDec(cn.taketoday.expression.spel.ast.OpDec) Nullable(cn.taketoday.lang.Nullable)

Example 3 with OpInc

use of cn.taketoday.expression.spel.ast.OpInc in project today-infrastructure by TAKETODAY.

the class InternalSpelExpressionParser method eatPowerIncDecExpression.

// powerExpr  : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
@Nullable
private SpelNodeImpl eatPowerIncDecExpression() {
    SpelNodeImpl expr = eatUnaryExpression();
    if (peekToken(TokenKind.POWER)) {
        // consume POWER
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatUnaryExpression();
        checkRightOperand(t, rhExpr);
        return new OperatorPower(t.startPos, t.endPos, expr, rhExpr);
    }
    if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
        // consume INC/DEC
        Token t = takeToken();
        if (t.kind == TokenKind.INC) {
            return new OpInc(t.startPos, t.endPos, true, expr);
        }
        return new OpDec(t.startPos, t.endPos, true, expr);
    }
    return expr;
}
Also used : OpInc(cn.taketoday.expression.spel.ast.OpInc) SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorPower(cn.taketoday.expression.spel.ast.OperatorPower) OpDec(cn.taketoday.expression.spel.ast.OpDec) Nullable(cn.taketoday.lang.Nullable)

Example 4 with OpInc

use of cn.taketoday.expression.spel.ast.OpInc in project today-infrastructure by TAKETODAY.

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.kind == 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(cn.taketoday.expression.spel.ast.OpInc) SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OpPlus(cn.taketoday.expression.spel.ast.OpPlus) OperatorNot(cn.taketoday.expression.spel.ast.OperatorNot) OpMinus(cn.taketoday.expression.spel.ast.OpMinus) OpDec(cn.taketoday.expression.spel.ast.OpDec) Nullable(cn.taketoday.lang.Nullable)

Aggregations

OpDec (cn.taketoday.expression.spel.ast.OpDec)4 OpInc (cn.taketoday.expression.spel.ast.OpInc)4 SpelNodeImpl (cn.taketoday.expression.spel.ast.SpelNodeImpl)4 Nullable (cn.taketoday.lang.Nullable)4 OpMinus (cn.taketoday.expression.spel.ast.OpMinus)2 OpPlus (cn.taketoday.expression.spel.ast.OpPlus)2 OperatorNot (cn.taketoday.expression.spel.ast.OperatorNot)2 OperatorPower (cn.taketoday.expression.spel.ast.OperatorPower)2