Search in sources :

Example 1 with WhileNode

use of org.mvel2.ast.WhileNode in project mvel by mvel.

the class AbstractParser method createBlockToken.

/**
 * Generate a code block token.
 *
 * @param condStart  the start offset for the condition
 * @param condEnd    the end offset for the condition
 * @param blockStart the start offset for the block
 * @param blockEnd   the end offset for the block
 * @param type       the type of block
 * @return and ast node
 */
private ASTNode createBlockToken(final int condStart, final int condEnd, final int blockStart, final int blockEnd, int type) {
    lastWasIdentifier = false;
    cursor++;
    if (isStatementNotManuallyTerminated()) {
        splitAccumulator.add(new EndOfStatement(pCtx));
    }
    int condOffset = condEnd - condStart;
    int blockOffset = blockEnd - blockStart;
    if (blockOffset < 0)
        blockOffset = 0;
    switch(type) {
        case ASTNode.BLOCK_IF:
            return new IfNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
        case ASTNode.BLOCK_FOR:
            for (int i = condStart; i < condEnd; i++) {
                if (expr[i] == ';')
                    return new ForNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
                else if (expr[i] == ':')
                    break;
            }
        case ASTNode.BLOCK_FOREACH:
            return new ForEachNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
        case ASTNode.BLOCK_WHILE:
            return new WhileNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
        case ASTNode.BLOCK_UNTIL:
            return new UntilNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
        case ASTNode.BLOCK_DO:
            return new DoNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
        case ASTNode.BLOCK_DO_UNTIL:
            return new DoUntilNode(expr, condStart, condOffset, blockStart, blockOffset, pCtx);
        default:
            return new WithNode(expr, condStart, condOffset, blockStart, blockOffset, fields, pCtx);
    }
}
Also used : UntilNode(org.mvel2.ast.UntilNode) DoUntilNode(org.mvel2.ast.DoUntilNode) ForNode(org.mvel2.ast.ForNode) EndOfStatement(org.mvel2.ast.EndOfStatement) DoNode(org.mvel2.ast.DoNode) WhileNode(org.mvel2.ast.WhileNode) ForEachNode(org.mvel2.ast.ForEachNode) IfNode(org.mvel2.ast.IfNode) DoUntilNode(org.mvel2.ast.DoUntilNode) WithNode(org.mvel2.ast.WithNode) ThisWithNode(org.mvel2.ast.ThisWithNode)

Aggregations

DoNode (org.mvel2.ast.DoNode)1 DoUntilNode (org.mvel2.ast.DoUntilNode)1 EndOfStatement (org.mvel2.ast.EndOfStatement)1 ForEachNode (org.mvel2.ast.ForEachNode)1 ForNode (org.mvel2.ast.ForNode)1 IfNode (org.mvel2.ast.IfNode)1 ThisWithNode (org.mvel2.ast.ThisWithNode)1 UntilNode (org.mvel2.ast.UntilNode)1 WhileNode (org.mvel2.ast.WhileNode)1 WithNode (org.mvel2.ast.WithNode)1