DeclarationParser { static Parser<Declaration> enumDef(Parser<Expression> expr, Parser<Member> member) { Parser<EnumDef.Value> enumValue = Parsers.sequence( Terminals.Identifier.PARSER, between(term("("), expr.sepBy(term(",")), term(")")) .optional(), between(term("{"), member.many(), term("}")).optional(), EnumDef.Value::new); return Parsers.sequence( StatementParser.modifier(expr).many(), term("enum").next(Terminals.Identifier.PARSER), term("implements").next(TypeLiteralParser.ELEMENT_TYPE_LITERAL.sepBy1(term(","))).optional(), term("{").next(enumValue.sepBy(term(","))), term(";").next(member.many()).optional().followedBy(term("}")), EnumDef::new); }  static Parser<Program> program(); static Program parse(String source); static Program parse(URL url);  }
@Test public void testEnumDef() { Parser<Declaration> parser = DeclarationParser.enumDef(IDENTIFIER, FIELD); TerminalParserTest.assertResult(parser, "enum Foo {}", EnumDef.class, "enum Foo {}"); TerminalParserTest.assertResult(parser, "enum Foo {FOO{int x;}}", EnumDef.class, "enum Foo {FOO {int x;}}"); TerminalParserTest.assertResult(parser, "@For(Test) enum Foo {}", EnumDef.class, "@For(Test) enum Foo {}"); TerminalParserTest.assertResult(parser, "enum Foo implements Comparable<Foo>, Serializable {}", EnumDef.class, "enum Foo implements Comparable<Foo>, Serializable {}"); TerminalParserTest.assertResult(parser, "enum Foo {ONE, TWO(two); int i; int j;}", EnumDef.class, "enum Foo {ONE, TWO(two); int i; int j;}"); TerminalParserTest.assertResult(parser, "enum Foo {ONE, TWO}", EnumDef.class, "enum Foo {ONE, TWO}"); }