StatementParser { static Parser<Statement> foreachStatement(Parser<Expression> expr, Parser<Statement> stmt) { return Parsers.sequence( phrase("for (").next(TypeLiteralParser.TYPE_LITERAL), Terminals.Identifier.PARSER, term(":").next(expr), term(")").next(stmt), ForeachStatement::new); }    }
@Test public void testForeachStatement() { Parser<Statement> parser = StatementParser.foreachStatement(ExpressionParser.IDENTIFIER, SIMPLE_STATEMENT); TerminalParserTest.assertResult(parser, "for(Foo foo : foos) bar;", ForeachStatement.class, "for (Foo foo : foos) bar;"); }