Search in sources :

Example 1 with NullLiteral

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

the class InternalSpelExpressionParser method maybeEatNullReference.

private boolean maybeEatNullReference() {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token nullToken = peekToken();
        Assert.state(nullToken != null, "Expected token");
        if (!"null".equalsIgnoreCase(nullToken.stringValue())) {
            return false;
        }
        nextToken();
        this.constructedNodes.push(new NullLiteral(nullToken.startPos, nullToken.endPos));
        return true;
    }
    return false;
}
Also used : NullLiteral(cn.taketoday.expression.spel.ast.NullLiteral)

Example 2 with NullLiteral

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

the class InternalSpelExpressionParser method eatExpression.

// expression
// : logicalOrExpression
// ( (ASSIGN^ logicalOrExpression)
// | (DEFAULT^ logicalOrExpression)
// | (QMARK^ expression COLON! expression)
// | (ELVIS^ expression))?;
@Nullable
private SpelNodeImpl eatExpression() {
    SpelNodeImpl expr = eatLogicalOrExpression();
    Token t = peekToken();
    if (t != null) {
        if (t.kind == TokenKind.ASSIGN) {
            // a=b
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
            }
            nextToken();
            SpelNodeImpl assignedValue = eatLogicalOrExpression();
            return new Assign(t.startPos, t.endPos, expr, assignedValue);
        }
        if (t.kind == TokenKind.ELVIS) {
            // a?:b (a if it isn't null, otherwise b)
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 2);
            }
            // elvis has left the building
            nextToken();
            SpelNodeImpl valueIfNull = eatExpression();
            if (valueIfNull == null) {
                valueIfNull = new NullLiteral(t.startPos + 1, t.endPos + 1);
            }
            return new Elvis(t.startPos, t.endPos, expr, valueIfNull);
        }
        if (t.kind == TokenKind.QMARK) {
            // a?b:c
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
            }
            nextToken();
            SpelNodeImpl ifTrueExprValue = eatExpression();
            eatToken(TokenKind.COLON);
            SpelNodeImpl ifFalseExprValue = eatExpression();
            return new Ternary(t.startPos, t.endPos, expr, ifTrueExprValue, ifFalseExprValue);
        }
    }
    return expr;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) Ternary(cn.taketoday.expression.spel.ast.Ternary) Elvis(cn.taketoday.expression.spel.ast.Elvis) Assign(cn.taketoday.expression.spel.ast.Assign) NullLiteral(cn.taketoday.expression.spel.ast.NullLiteral) Nullable(cn.taketoday.lang.Nullable)

Example 3 with NullLiteral

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

the class InternalSpelExpressionParser method eatExpression.

// expression
// : logicalOrExpression
// ( (ASSIGN^ logicalOrExpression)
// | (DEFAULT^ logicalOrExpression)
// | (QMARK^ expression COLON! expression)
// | (ELVIS^ expression))?;
@Nullable
private SpelNodeImpl eatExpression() {
    SpelNodeImpl expr = eatLogicalOrExpression();
    Token t = peekToken();
    if (t != null) {
        if (t.kind == TokenKind.ASSIGN) {
            // a=b
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
            }
            nextToken();
            SpelNodeImpl assignedValue = eatLogicalOrExpression();
            return new Assign(t.startPos, t.endPos, expr, assignedValue);
        }
        if (t.kind == TokenKind.ELVIS) {
            // a?:b (a if it isn't null, otherwise b)
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 2);
            }
            // elvis has left the building
            nextToken();
            SpelNodeImpl valueIfNull = eatExpression();
            if (valueIfNull == null) {
                valueIfNull = new NullLiteral(t.startPos + 1, t.endPos + 1);
            }
            return new Elvis(t.startPos, t.endPos, expr, valueIfNull);
        }
        if (t.kind == TokenKind.QMARK) {
            // a?b:c
            if (expr == null) {
                expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
            }
            nextToken();
            SpelNodeImpl ifTrueExprValue = eatExpression();
            eatToken(TokenKind.COLON);
            SpelNodeImpl ifFalseExprValue = eatExpression();
            return new Ternary(t.startPos, t.endPos, expr, ifTrueExprValue, ifFalseExprValue);
        }
    }
    return expr;
}
Also used : SpelNodeImpl(cn.taketoday.expression.spel.ast.SpelNodeImpl) Ternary(cn.taketoday.expression.spel.ast.Ternary) Elvis(cn.taketoday.expression.spel.ast.Elvis) Assign(cn.taketoday.expression.spel.ast.Assign) NullLiteral(cn.taketoday.expression.spel.ast.NullLiteral) Nullable(cn.taketoday.lang.Nullable)

Example 4 with NullLiteral

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

the class InternalSpelExpressionParser method maybeEatNullReference.

private boolean maybeEatNullReference() {
    if (peekToken(TokenKind.IDENTIFIER)) {
        Token nullToken = peekToken();
        Assert.state(nullToken != null, "Expected token");
        if (!"null".equalsIgnoreCase(nullToken.stringValue())) {
            return false;
        }
        nextToken();
        this.constructedNodes.push(new NullLiteral(nullToken.startPos, nullToken.endPos));
        return true;
    }
    return false;
}
Also used : NullLiteral(cn.taketoday.expression.spel.ast.NullLiteral)

Aggregations

NullLiteral (cn.taketoday.expression.spel.ast.NullLiteral)4 Assign (cn.taketoday.expression.spel.ast.Assign)2 Elvis (cn.taketoday.expression.spel.ast.Elvis)2 SpelNodeImpl (cn.taketoday.expression.spel.ast.SpelNodeImpl)2 Ternary (cn.taketoday.expression.spel.ast.Ternary)2 Nullable (cn.taketoday.lang.Nullable)2