ExpressionParser extends UserExpressionParser { @Override public UserExpression parse(final String expression) { try { final ExprParser parser = new ExprParser(new CommonTokenStream(new ExprLexer(new ANTLRReaderStream(new StringReader(expression))))) { @Override public void reportError(final RecognitionException e) { throw new OpenGammaRuntimeException(e.getMessage()); } }; final ExprParser.root_return root = parser.root(); return build(((Tree) root.getTree()).getChild(0)); } catch (Throwable e) { s_logger.warn("Couldn't parse expression {} - {}", expression, e); throw new IllegalArgumentException(expression); } } ExpressionParser(); @Override void setConstant(final String var, final Object value); @Override void setFunction(final String object, final String name, final Method method); @Override UserExpression parse(final String expression);  }
@Test(expectedExceptions = {IllegalArgumentException.class }) public void testEmptyString() { final UserExpression expr = new ExpressionParser().parse(""); }
@Test(expectedExceptions = {IllegalArgumentException.class }) public void testIllegalString() { final UserExpression expr = new ExpressionParser().parse("Foo less \"Bar\""); }
@Test public void testAttributeEquality() { parse("Foo=\"Bar\"", "`EQ (`IDENTIFIER Foo) (`LITERAL Bar)"); }
@Test public void testAttributeLessThan() { parse("Foo<\"B\\\"ar\"", "`LT (`IDENTIFIER Foo) (`LITERAL B\"ar)"); }
@Test public void testAttributeGreaterThan() { parse("Foo>\"Bar\"", "`GT (`IDENTIFIER Foo) (`LITERAL Bar)"); }
@Test public void testAttributeNotEqual() { parse("Foo<>\"Bar\"", "`NEQ (`IDENTIFIER Foo) (`LITERAL Bar)"); }
@Test public void testNot() { parse("NOT Foo=\"Bar\"", "`NOT (`EQ (`IDENTIFIER Foo) (`LITERAL Bar))"); }
@Test public void testAnd() { parse("Foo=\"Bar\" AND Bar=\"Foo\" AND Cow=\"Foo\"", "`AND (`EQ (`IDENTIFIER Foo) (`LITERAL Bar)) (`AND (`EQ (`IDENTIFIER Bar) (`LITERAL Foo)) (`EQ (`IDENTIFIER Cow) (`LITERAL Foo)))"); }
@Test public void testOr() { parse("Foo=\"Bar\" OR Foo=\"Cow\" OR Bar=\"Cow\"", "`OR (`EQ (`IDENTIFIER Foo) (`LITERAL Bar)) (`OR (`EQ (`IDENTIFIER Foo) (`LITERAL Cow)) (`EQ (`IDENTIFIER Bar) (`LITERAL Cow)))"); }
@Test public void testBrackets() { parse("(((Foo=\"Bar\") AND (Bar=\"Foo\")) OR ((Foo=\"Bar\") AND (Bar=\"Cow\")))", "`OR (`AND (`EQ (`IDENTIFIER Foo) (`LITERAL Bar)) (`EQ (`IDENTIFIER Bar) (`LITERAL Foo))) (`AND (`EQ (`IDENTIFIER Foo) (`LITERAL Bar)) (`EQ (`IDENTIFIER Bar) (`LITERAL Cow)))"); }