diff --git a/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4 b/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4 index eee648602..737ad4b6b 100644 --- a/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4 +++ b/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4 @@ -132,7 +132,9 @@ TRUE : 'true'; FALSE : 'false'; BOOLEAN : T R U E | F A L S E; PLUS : '+'; -SIGN : PLUS | '%2B' |'-'; + +MINUS : '-'; +SIGN : PLUS | '%2B' | '-'; INT : SIGN? DIGITS; DECIMAL : INT '.' DIGITS (('e'|'E') SIGN? DIGITS)?; NANINFINITY : 'NaN' | '-INF' | 'INF'; @@ -184,7 +186,7 @@ OR : 'or'; NOT : 'not'; -MINUS :'-'; + IT : '$it'; ITSLASH : '$it/'; diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java index ff19f3e0c..2c3d87c6d 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java @@ -2166,8 +2166,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { @Override public ExpressionImpl visitAltUnary(@NotNull UriParserParser.AltUnaryContext ctx) { UnaryImpl unary = new UnaryImpl(); - unary.setOperator(ctx.unary().NOT() == null?UnaryOperatorKind.MINUS:UnaryOperatorKind.NOT); - unary.setOperand((ExpressionImpl)ctx.commonExpr().accept(this)); + unary.setOperator(ctx.unary().NOT() == null? UnaryOperatorKind.MINUS: UnaryOperatorKind.NOT); + unary.setOperand((ExpressionImpl) ctx.commonExpr().accept(this)); return unary; } @@ -2177,5 +2177,4 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { alias.setParameter("@"+ctx.odataIdentifier().getChild(0).getText()); return alias; } - } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java index e8aa9cecd..76c11aa59 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java @@ -48,6 +48,11 @@ public class TestLexer { // ; 0. URI // ;------------------------------------------------------------------------------ + @Test + public void testUnary() { + test.run("- a eq a").isAllInput(); + } + @Test public void testUriTokens() { test.globalMode(UriLexer.MODE_QUERY); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java index 1ccebbb5b..30e1b0da4 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java @@ -566,6 +566,12 @@ public class TestUriParserImpl { } + @Test + public void testUnary() throws UriParserException { + testFilter.runESabc("not a").isCompr(">"); + testFilter.runESabc("- a eq a").isCompr("<<- > eq >"); + } + @Test public void testFilterComplexMixedPriority() throws UriParserException { testFilter.runESabc("a or c and e ").isCompr("< or < and >>"); @@ -576,7 +582,6 @@ public class TestUriParserImpl { testFilter.runESabc("a eq b or c and e eq f").isCompr("<< eq > or < and < eq >>>"); testFilter.runESabc("a eq b or c eq d and e ").isCompr("<< eq > or << eq > and >>"); testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<< eq > or << eq > and < eq >>>"); - testFilter.runESabc("not a").isCompr(">"); } @Test @@ -1055,7 +1060,7 @@ public class TestUriParserImpl { @Test public void testAlias() throws Exception { - testUri.run("ESAllPrim?$filter=PropertyInt16 eq @p1&@p1=1)") + testUri.run("ESAllPrim", "$filter=PropertyInt16 eq @p1&@p1=1)") .goFilter().is("< eq <@p1>>"); }