RelationParser { static Parser<Relation> union(Parser<Relation> rel) { Parser.Reference<Relation> ref = Parser.newReference(); Parser<Relation> parser = ExpressionParser.paren(ref.lazy()).or(rel).infixl( TerminalParser.term("union").next(TerminalParser.term("all").succeeds()) .label("relation") .map(a -> (l, r) -> new UnionRelation(l, a, r))); ref.set(parser); return parser; }  static Parser<Relation> query();  }
@Test public void testUnion() { Parser<Relation> parser = RelationParser.union(TABLE); TerminalParserTest.assertParser(parser, "a", table("a")); TerminalParserTest.assertParser(parser, "a union b", new UnionRelation(table("a"), false, table("b"))); TerminalParserTest.assertParser(parser, "a union all b union (c)", new UnionRelation( new UnionRelation(table("a"), true, table("b")), false, table("c") ) ); TerminalParserTest.assertParser(parser, "a union all (b union (c))", new UnionRelation( table("a"), true, new UnionRelation(table("b"), false, table("c")) ) ); }