DeclarationParser { static Parser<Member> fieldDef(Parser<Expression> initializer) { return Parsers.sequence( StatementParser.modifier(initializer).many(), TypeLiteralParser.TYPE_LITERAL, Terminals.Identifier.PARSER, term("=").next(ExpressionParser.arrayInitializerOrRegularExpression(initializer)) .optional(), term(";"), (modifiers, type, name, value, __) -> new FieldDef(modifiers, type, name ,value)); }  static Parser<Program> program(); static Program parse(String source); static Program parse(URL url);  }
@Test public void testFieldDef() { TerminalParserTest.assertResult(FIELD, "int f;", FieldDef.class, "int f;"); TerminalParserTest.assertResult(FIELD, "static final int f;", FieldDef.class, "static final int f;"); TerminalParserTest.assertResult(FIELD, "int f = foo;", FieldDef.class, "int f = foo;"); TerminalParserTest.assertResult(FIELD, "int[] a = {foo};", FieldDef.class, "int[] a = {foo};"); }