Search in sources :

Example 1 with WhileStatement

use of org.codehaus.groovy.ast.stmt.WhileStatement in project groovy by apache.

the class AntlrParserPlugin method statement.

// Statements
//-------------------------------------------------------------------------
protected Statement statement(AST node) {
    Statement statement = null;
    int type = node.getType();
    switch(type) {
        case SLIST:
        case LITERAL_finally:
            statement = statementList(node);
            break;
        case METHOD_CALL:
            statement = methodCall(node);
            break;
        case VARIABLE_DEF:
            statement = variableDef(node);
            break;
        case LABELED_STAT:
            return labelledStatement(node);
        case LITERAL_assert:
            statement = assertStatement(node);
            break;
        case LITERAL_break:
            statement = breakStatement(node);
            break;
        case LITERAL_continue:
            statement = continueStatement(node);
            break;
        case LITERAL_if:
            statement = ifStatement(node);
            break;
        case LITERAL_for:
            statement = forStatement(node);
            break;
        case LITERAL_return:
            statement = returnStatement(node);
            break;
        case LITERAL_synchronized:
            statement = synchronizedStatement(node);
            break;
        case LITERAL_switch:
            statement = switchStatement(node);
            break;
        case LITERAL_try:
            statement = tryStatement(node);
            break;
        case LITERAL_throw:
            statement = throwStatement(node);
            break;
        case LITERAL_while:
            statement = whileStatement(node);
            break;
        default:
            statement = new ExpressionStatement(expression(node));
    }
    if (statement != null) {
        configureAST(statement, node);
    }
    return statement;
}
Also used : CaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement) ForStatement(org.codehaus.groovy.ast.stmt.ForStatement) CatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) AssertStatement(org.codehaus.groovy.ast.stmt.AssertStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) Statement(org.codehaus.groovy.ast.stmt.Statement) WhileStatement(org.codehaus.groovy.ast.stmt.WhileStatement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement) ContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement) BreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) SynchronizedStatement(org.codehaus.groovy.ast.stmt.SynchronizedStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) TryCatchStatement(org.codehaus.groovy.ast.stmt.TryCatchStatement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement)

Example 2 with WhileStatement

use of org.codehaus.groovy.ast.stmt.WhileStatement in project groovy by apache.

the class AntlrParserPlugin method whileStatement.

protected Statement whileStatement(AST whileNode) {
    AST node = whileNode.getFirstChild();
    assertNodeType(EXPR, node);
    // TODO remove this once we support declarations in the while condition
    if (isType(VARIABLE_DEF, node.getFirstChild())) {
        throw new ASTRuntimeException(whileNode, "While loop condition contains a declaration; this is currently unsupported.");
    }
    BooleanExpression booleanExpression = booleanExpression(node);
    node = node.getNextSibling();
    Statement block;
    if (isType(SEMI, node)) {
        block = EmptyStatement.INSTANCE;
    } else {
        block = statement(node);
    }
    WhileStatement whileStatement = new WhileStatement(booleanExpression, block);
    configureAST(whileStatement, whileNode);
    return whileStatement;
}
Also used : AST(antlr.collections.AST) CaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement) ForStatement(org.codehaus.groovy.ast.stmt.ForStatement) CatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) AssertStatement(org.codehaus.groovy.ast.stmt.AssertStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) Statement(org.codehaus.groovy.ast.stmt.Statement) WhileStatement(org.codehaus.groovy.ast.stmt.WhileStatement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement) ContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement) BreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) SynchronizedStatement(org.codehaus.groovy.ast.stmt.SynchronizedStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) TryCatchStatement(org.codehaus.groovy.ast.stmt.TryCatchStatement) WhileStatement(org.codehaus.groovy.ast.stmt.WhileStatement)

Aggregations

AssertStatement (org.codehaus.groovy.ast.stmt.AssertStatement)2 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)2 BreakStatement (org.codehaus.groovy.ast.stmt.BreakStatement)2 CaseStatement (org.codehaus.groovy.ast.stmt.CaseStatement)2 CatchStatement (org.codehaus.groovy.ast.stmt.CatchStatement)2 ContinueStatement (org.codehaus.groovy.ast.stmt.ContinueStatement)2 EmptyStatement (org.codehaus.groovy.ast.stmt.EmptyStatement)2 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)2 ForStatement (org.codehaus.groovy.ast.stmt.ForStatement)2 IfStatement (org.codehaus.groovy.ast.stmt.IfStatement)2 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)2 Statement (org.codehaus.groovy.ast.stmt.Statement)2 SwitchStatement (org.codehaus.groovy.ast.stmt.SwitchStatement)2 SynchronizedStatement (org.codehaus.groovy.ast.stmt.SynchronizedStatement)2 ThrowStatement (org.codehaus.groovy.ast.stmt.ThrowStatement)2 TryCatchStatement (org.codehaus.groovy.ast.stmt.TryCatchStatement)2 WhileStatement (org.codehaus.groovy.ast.stmt.WhileStatement)2 AST (antlr.collections.AST)1