Parser { protected AstExpr expr() { AstExpr expr = primary(); if (lexer.token() == Token.COMMA) { return expr; } return exprRest(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 testMultiExpr() { Parser parser = new Parser("1 2"); AstExpr expr = parser.expr(); System.out.println(expr); }
@Test public void testAdd() throws Exception { String text = "a + b"; Parser parser = new Parser(text); AstExpr expr = parser.expr(); AstBinary binaryExpr = (AstBinary) expr; AstIdentifier left = (AstIdentifier) binaryExpr.getLeft(); AstIdentifier right = (AstIdentifier) binaryExpr.getRight(); assertEquals("a", left.getName()); assertEquals("b", right.getName()); }
@Test public void testDiv() throws Exception { String text = "a / b"; Parser parser = new Parser(text); AstExpr expr = parser.expr(); AstBinary binaryExpr = (AstBinary) expr; AstIdentifier left = (AstIdentifier) binaryExpr.getLeft(); AstIdentifier right = (AstIdentifier) binaryExpr.getRight(); assertEquals("a", left.getName()); assertEquals("b", right.getName()); assertEquals(expr.toString(), text); }
@Test public void testRightShift() throws Exception { String text = "a >> b"; Parser parser = new Parser(text); AstExpr expr = parser.expr(); AstBinary binaryExpr = (AstBinary) expr; AstIdentifier left = (AstIdentifier) binaryExpr.getLeft(); AstIdentifier right = (AstIdentifier) binaryExpr.getRight(); assertEquals("a", left.getName()); assertEquals("b", right.getName()); assertEquals(expr.toString(), text); }
@Test public void testLeftShift() throws Exception { String text = "a << 3"; Parser parser = new Parser(text); AstExpr expr = parser.expr(); AstBinary binaryExpr = (AstBinary) expr; AstIdentifier left = (AstIdentifier) binaryExpr.getLeft(); AstNumber right = (AstNumber) binaryExpr.getRight(); assertEquals("a", left.getName()); assertEquals(3, right.getValue()); assertEquals(expr.toString(), text); }
@Test public void testSub() throws Exception { String text = "+1 + +2.0 + -1 + -1.3"; Parser parser = new Parser(text); AstExpr expr = parser.expr(); assertEquals("1 + 2.0 + -1 + -1.3", expr.toString()); }