Parser { public static AstExpr parse(String text) { return new Parser(text).expr(); } Parser(String input);  Parser(ElParseContext context, String input); static AstExpr parse(String text); static AstExpr parse(ElParseContext context, String text); AstExpr parse(); AstExpr parse(boolean allowRest); boolean eof(); String rest(); AstExpr relationalRest(AstExpr expr); AstExpr primary(); AstExpr primaryRest(AstExpr expr);  }
@Test public void testChoice() { AstExpr expr = Parser.parse("a ? b : c"); AstChoice cexpr = (AstChoice)expr; AstIdentifier condition = (AstIdentifier)cexpr.getQuestion(); AstIdentifier trueValue = (AstIdentifier)cexpr.getYes(); AstIdentifier falseValue = (AstIdentifier)cexpr.getNo(); assertEquals("a",condition.getName()); assertEquals("b",trueValue.getName()); assertEquals("c",falseValue.getName()); }
@Test public void testFunction() { AstBinary expr = parse("1 + a(1)"); AstFunction func = (AstFunction)expr.getRight(); assertNull(func.getPrefix()); assertEquals("a",func.getName()); func = parse("p:a()"); assertEquals("p", func.getPrefix()); assertEquals("a", func.getName()); expr = parse("1 + p:a (1,2,'3')"); func = (AstFunction)expr.getRight(); assertEquals("p", func.getPrefix()); assertEquals("a", func.getName()); }
@Test public void testItem() { AstItem p = parse("a['p']"); assertTrue(p.getIndex() instanceof AstString); p = parse("a[p]"); assertTrue(p.getIndex() instanceof AstIdentifier); p = parse("a[o.p]"); assertTrue(p.getIndex() instanceof AstProperty); }