Search in sources :

Example 1 with OperatorMatches

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

the class InternalSpelExpressionParser method eatRelationalExpression.

// relationalExpression : sumExpression (relationalOperator^ sumExpression)?;
@Nullable
private SpelNodeImpl eatRelationalExpression() {
    SpelNodeImpl expr = eatSumExpression();
    Token relationalOperatorToken = maybeEatRelationalOperator();
    if (relationalOperatorToken != null) {
        // consume relational operator token
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatSumExpression();
        checkOperands(t, expr, rhExpr);
        TokenKind tk = relationalOperatorToken.kind;
        if (relationalOperatorToken.isNumericRelationalOperator()) {
            if (tk == TokenKind.GT) {
                return new OpGT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LT) {
                return new OpLT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LE) {
                return new OpLE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.GE) {
                return new OpGE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.EQ) {
                return new OpEQ(t.startPos, t.endPos, expr, rhExpr);
            }
            Assert.isTrue(tk == TokenKind.NE, "Not-equals token expected");
            return new OpNE(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.INSTANCEOF) {
            return new OperatorInstanceof(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.MATCHES) {
            return new OperatorMatches(t.startPos, t.endPos, expr, rhExpr);
        }
        Assert.isTrue(tk == TokenKind.BETWEEN, "Between token expected");
        return new OperatorBetween(t.startPos, t.endPos, expr, rhExpr);
    }
    return expr;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorInstanceof(cn.taketoday.expression.spel.ast.OperatorInstanceof) OpEQ(cn.taketoday.expression.spel.ast.OpEQ) OpGE(cn.taketoday.expression.spel.ast.OpGE) OpGT(cn.taketoday.expression.spel.ast.OpGT) OpLT(cn.taketoday.expression.spel.ast.OpLT) OperatorMatches(cn.taketoday.expression.spel.ast.OperatorMatches) OpNE(cn.taketoday.expression.spel.ast.OpNE) OpLE(cn.taketoday.expression.spel.ast.OpLE) OperatorBetween(cn.taketoday.expression.spel.ast.OperatorBetween) Nullable(cn.taketoday.lang.Nullable)

Example 2 with OperatorMatches

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

the class InternalSpelExpressionParser method eatRelationalExpression.

// relationalExpression : sumExpression (relationalOperator^ sumExpression)?;
@Nullable
private SpelNodeImpl eatRelationalExpression() {
    SpelNodeImpl expr = eatSumExpression();
    Token relationalOperatorToken = maybeEatRelationalOperator();
    if (relationalOperatorToken != null) {
        // consume relational operator token
        Token t = takeToken();
        SpelNodeImpl rhExpr = eatSumExpression();
        checkOperands(t, expr, rhExpr);
        TokenKind tk = relationalOperatorToken.kind;
        if (relationalOperatorToken.isNumericRelationalOperator()) {
            if (tk == TokenKind.GT) {
                return new OpGT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LT) {
                return new OpLT(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.LE) {
                return new OpLE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.GE) {
                return new OpGE(t.startPos, t.endPos, expr, rhExpr);
            }
            if (tk == TokenKind.EQ) {
                return new OpEQ(t.startPos, t.endPos, expr, rhExpr);
            }
            Assert.isTrue(tk == TokenKind.NE, "Not-equals token expected");
            return new OpNE(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.INSTANCEOF) {
            return new OperatorInstanceof(t.startPos, t.endPos, expr, rhExpr);
        }
        if (tk == TokenKind.MATCHES) {
            return new OperatorMatches(t.startPos, t.endPos, expr, rhExpr);
        }
        Assert.isTrue(tk == TokenKind.BETWEEN, "Between token expected");
        return new OperatorBetween(t.startPos, t.endPos, expr, rhExpr);
    }
    return expr;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) OperatorInstanceof(cn.taketoday.expression.spel.ast.OperatorInstanceof) OpEQ(cn.taketoday.expression.spel.ast.OpEQ) OpGE(cn.taketoday.expression.spel.ast.OpGE) OpGT(cn.taketoday.expression.spel.ast.OpGT) OpLT(cn.taketoday.expression.spel.ast.OpLT) OperatorMatches(cn.taketoday.expression.spel.ast.OperatorMatches) OpNE(cn.taketoday.expression.spel.ast.OpNE) OpLE(cn.taketoday.expression.spel.ast.OpLE) OperatorBetween(cn.taketoday.expression.spel.ast.OperatorBetween) Nullable(cn.taketoday.lang.Nullable)

Aggregations

OpEQ (cn.taketoday.expression.spel.ast.OpEQ)2 OpGE (cn.taketoday.expression.spel.ast.OpGE)2 OpGT (cn.taketoday.expression.spel.ast.OpGT)2 OpLE (cn.taketoday.expression.spel.ast.OpLE)2 OpLT (cn.taketoday.expression.spel.ast.OpLT)2 OpNE (cn.taketoday.expression.spel.ast.OpNE)2 OperatorBetween (cn.taketoday.expression.spel.ast.OperatorBetween)2 OperatorInstanceof (cn.taketoday.expression.spel.ast.OperatorInstanceof)2 OperatorMatches (cn.taketoday.expression.spel.ast.OperatorMatches)2 SpelNodeImpl (cn.taketoday.expression.spel.ast.SpelNodeImpl)2 Nullable (cn.taketoday.lang.Nullable)2