StatementParser { static Parser<Statement> forStatement(Parser<Expression> expr, Parser<Statement> stmt) { return Parsers.sequence( phrase("for (").next(Parsers.or(varStatement(expr), expressionList(expr), NOP)), expr.optional(), between(term(";"), expr.sepBy(term(",")), term(")")), stmt, ForStatement::new); }    }
@Test public void testForStatement() { Parser<Statement> parser = StatementParser.forStatement(ExpressionParser.IDENTIFIER, SIMPLE_STATEMENT); TerminalParserTest.assertResult(parser, "for(;;)foo;", ForStatement.class, "for (;;) foo;"); TerminalParserTest.assertResult(parser, "for(int i=m;;)foo;", ForStatement.class, "for (int i = m;;) foo;"); TerminalParserTest.assertResult(parser, "for(init;;)foo;", ForStatement.class, "for (init;;) foo;"); TerminalParserTest.assertResult(parser, "for(init1,init2;;)foo;", ForStatement.class, "for (init1, init2;;) foo;"); TerminalParserTest.assertResult(parser, "for(;cond;)foo;", ForStatement.class, "for (;cond;) foo;"); TerminalParserTest.assertResult(parser, "for(;;a)foo;", ForStatement.class, "for (;;a) foo;"); TerminalParserTest.assertResult(parser, "for(;;a,b)foo;", ForStatement.class, "for (;;a, b) foo;"); TerminalParserTest.assertResult(parser, "for(int i=m, j=n;cond;a,b)foo;", ForStatement.class, "for (int i = m, j = n;cond;a, b) foo;"); }