Search in sources :

Example 11 with SpelNodeImpl

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

the class InternalSpelExpressionParser method doParseExpression.

@Override
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
    try {
        this.expressionString = expressionString;
        Tokenizer tokenizer = new Tokenizer(expressionString);
        tokenizer.process();
        this.tokenStream = tokenizer.getTokens();
        this.tokenStreamLength = this.tokenStream.size();
        this.tokenStreamPointer = 0;
        this.constructedNodes.clear();
        SpelNodeImpl ast = eatExpression();
        if (moreTokens()) {
            throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken()));
        }
        Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected");
        return new SpelExpression(expressionString, ast, this.configuration);
    } catch (InternalParseException ex) {
        throw ex.getCause();
    }
}
Also used : SpelParseException(org.springframework.expression.spel.SpelParseException) InternalParseException(org.springframework.expression.spel.InternalParseException) SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl)

Example 12 with SpelNodeImpl

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

the class InternalSpelExpressionParser method maybeEatParenExpression.

//parenExpr : LPAREN! expression RPAREN!;
private boolean maybeEatParenExpression() {
    if (peekToken(TokenKind.LPAREN)) {
        nextToken();
        SpelNodeImpl expr = eatExpression();
        eatToken(TokenKind.RPAREN);
        push(expr);
        return true;
    } else {
        return false;
    }
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl)

Example 13 with SpelNodeImpl

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

the class InternalSpelExpressionParser method eatUnaryExpression.

// unaryExpression: (PLUS^ | MINUS^ | BANG^ | INC^ | DEC^) unaryExpression | primaryExpression ;
private SpelNodeImpl eatUnaryExpression() {
    if (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.NOT)) {
        Token t = nextToken();
        SpelNodeImpl expr = eatUnaryExpression();
        if (t.kind == TokenKind.NOT) {
            return new OperatorNot(toPos(t), expr);
        }
        if (t.kind == TokenKind.PLUS) {
            return new OpPlus(toPos(t), expr);
        }
        Assert.isTrue(t.kind == TokenKind.MINUS, "Minus token expected");
        return new OpMinus(toPos(t), expr);
    }
    if (peekToken(TokenKind.INC, TokenKind.DEC)) {
        Token t = nextToken();
        SpelNodeImpl expr = eatUnaryExpression();
        if (t.getKind() == TokenKind.INC) {
            return new OpInc(toPos(t), false, expr);
        }
        return new OpDec(toPos(t), 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)

Example 14 with SpelNodeImpl

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

the class InternalSpelExpressionParser method eatPossiblyQualifiedId.

/**
	 * Eat an identifier, possibly qualified (meaning that it is dotted).
	 * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c)
	 */
private SpelNodeImpl eatPossiblyQualifiedId() {
    LinkedList<SpelNodeImpl> qualifiedIdPieces = new LinkedList<>();
    Token node = peekToken();
    while (isValidQualifiedId(node)) {
        nextToken();
        if (node.kind != TokenKind.DOT) {
            qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node)));
        }
        node = peekToken();
    }
    if (qualifiedIdPieces.isEmpty()) {
        if (node == null) {
            raiseInternalException(this.expressionString.length(), SpelMessage.OOD);
        }
        raiseInternalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase());
    }
    int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition());
    return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[qualifiedIdPieces.size()]));
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) Identifier(org.springframework.expression.spel.ast.Identifier) QualifiedIdentifier(org.springframework.expression.spel.ast.QualifiedIdentifier) QualifiedIdentifier(org.springframework.expression.spel.ast.QualifiedIdentifier) LinkedList(java.util.LinkedList)

Example 15 with SpelNodeImpl

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

the class InternalSpelExpressionParser method eatPrimaryExpression.

// primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?);
private SpelNodeImpl eatPrimaryExpression() {
    List<SpelNodeImpl> nodes = new ArrayList<>();
    // always a start node
    SpelNodeImpl start = eatStartNode();
    nodes.add(start);
    while (maybeEatNode()) {
        nodes.add(pop());
    }
    if (nodes.size() == 1) {
        return nodes.get(0);
    }
    return new CompoundExpression(toPos(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition()), nodes.toArray(new SpelNodeImpl[nodes.size()]));
}
Also used : SpelNodeImpl(org.springframework.expression.spel.ast.SpelNodeImpl) CompoundExpression(org.springframework.expression.spel.ast.CompoundExpression) ArrayList(java.util.ArrayList)

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