ExpressionParser { static Parser<Expression> expression(Parser<Expression> cond) { Parser.Reference<Expression> reference = Parser.newReference(); Parser<Expression> lazyExpr = reference.lazy(); Parser<Expression> atom = Parsers.or( NUMBER, WILDCARD, QUALIFIED_NAME, simpleCase(lazyExpr), fullCase(cond, lazyExpr)); Parser<Expression> expression = arithmetic(atom).label("expression"); reference.set(expression); return expression; }    }
@Test public void testExpression() { Parser<Expression> parser = ExpressionParser.expression(NUMBER); TerminalParserTest.assertParser(parser, "1 + case a when a then count(a.b.*) end - case when 1 then a * 2 else b end", new BinaryExpression( new BinaryExpression( number(1), Op.PLUS, simpleCase(name("a"), name("a"), function("count", wildcard("a", "b")), null)), Op.MINUS, fullCase(number(1), new BinaryExpression(name("a"), Op.MUL, number(2)), name("b")) ) ); }