RuleParser { static Parser<Rule> rule() { Parser.Reference<Rule> ref = Parser.newReference(); Parser<Rule> atom = Parsers.or(LITERAL, IDENT, unit(ref.lazy())); Parser<Rule> parser = alternative(sequential(atom)); ref.set(parser); return parser; }   static Parser<List<RuleDef>> RULE_DEFS; }
@Test public void testRule() { Parser<Rule> parser = RuleParser.rule(); assertParser(parser, "foo", RuleReference.class, "foo"); assertParser(parser, "'foo'", LiteralRule.class, "'foo'"); assertParser(parser, "foo bar", SequentialRule.class, "foo bar"); assertParser(parser, "foo bar | baz |'foo'", AltRule.class, "(foo bar | baz | 'foo')"); assertParser(parser, "foo bar | \n baz |'foo'", AltRule.class, "(foo bar | (baz | 'foo'))"); assertParser(parser, "foo bar baz |'foo'", AltRule.class, "(foo bar baz | 'foo')"); assertParser(parser, "foo bar \n baz |'foo'", SequentialRule.class, "foo bar (baz | 'foo')"); assertParser(parser, "foo bar (baz |'foo')", SequentialRule.class, "foo bar (baz | 'foo')"); assertParser(parser, "foo \n| bar", AltRule.class, "(foo | bar)"); assertParser(parser, "foo | \n bar | baz \n| 'foo'", AltRule.class, "(foo | (bar | baz) | 'foo')"); }