ExpressionParser { static Parser<Expression> fullCase(Parser<Expression> cond, Parser<Expression> expr) { return Parsers.sequence( term("case").next(whenThens(cond, expr)), term("else").next(expr).optional().followedBy(term("end")), FullCaseExpression::new); }    }
@Test public void testFullCase() { Parser<Expression> parser = ExpressionParser.fullCase(ExpressionParser.QUALIFIED_NAME, NUMBER); TerminalParserTest.assertParser(parser, "case when a then 2 else 3 end", fullCase(name("a"), number(2), number(3))); TerminalParserTest.assertParser(parser, "case when a then 2 end", fullCase(name("a"), number(2), null)); }