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;
}
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;
}
Aggregations