ExpressionParser { static Parser<Expression> newArrayWithExplicitLength(Parser<Expression> expr) { return Parsers.sequence(term("new").next(TypeLiteralParser.TYPE_LITERAL), expr.between(term("["), term("]")), Parsers.between(term("{"), expr.sepBy(term(",")), term("}")).optional(), NewArrayExpression::new); }  static Parser<Expression> expression(
      Parser<DefBody> classBody, Parser<Statement> statement); static Parser<Expression> arrayInitializer(Parser<Expression> expr);  }
@Test public void testNewArrayWithExplicitLength() { Parser<Expression> parser = ExpressionParser.newArrayWithExplicitLength(ExpressionParser.IDENTIFIER); TerminalParserTest.assertResult(parser, "new int[n]", NewArrayExpression.class, "new int[n]"); TerminalParserTest.assertResult(parser, "new int[][n]", NewArrayExpression.class, "new int[][n]"); TerminalParserTest.assertResult(parser, "new int[n]{}", NewArrayExpression.class, "new int[n] {}"); TerminalParserTest.assertResult(parser, "new int[n]{a,b,c}", NewArrayExpression.class, "new int[n] {a, b, c}"); }