From 93701c6d1a692582429fd96ab4fcce3108cc5408 Mon Sep 17 00:00:00 2001 From: obickus Date: Fri, 19 Nov 2021 15:49:46 +0200 Subject: [PATCH] Fix parsing for boolean expressions starting with negation --- .../io/burt/jmespath/parser/JmesPath.g4 | 2 +- .../io/burt/jmespath/parser/ParserTest.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4 b/jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4 index 56469956..8d6dc5f4 100644 --- a/jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4 +++ b/jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4 @@ -7,10 +7,10 @@ expression | expression bracketSpecifier # bracketedExpression | bracketSpecifier # bracketExpression | expression COMPARATOR expression # comparisonExpression + | '!' expression # notExpression | expression '&&' expression # andExpression | expression '||' expression # orExpression | identifier # identifierExpression - | '!' expression # notExpression | '(' expression ')' # parenExpression | wildcard # wildcardExpression | multiSelectList # multiSelectListExpression diff --git a/jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java b/jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java index bdfa72b3..0597b06b 100644 --- a/jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java +++ b/jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java @@ -805,6 +805,32 @@ public void bareNegatedExpression() { assertThat(actual, is(expected)); } + @Test + public void negatedBooleansTripleConjunctionExpression() { + Expression expected = And( + And( + Negate(Property("foo")), + Negate(Property("bar")) + ), + Negate(Property("buzz")) + ); + Expression actual = compile("!foo && !bar && !buzz"); + assertThat(actual, is(expected)); + } + + @Test + public void negatedBooleansTripleDisjunctionExpression() { + Expression expected = Or( + Or( + Negate(Property("foo")), + Negate(Property("bar")) + ), + Negate(Property("buzz")) + ); + Expression actual = compile("!foo || !bar || !buzz"); + assertThat(actual, is(expected)); + } + @Test public void negatedSelectionExpression() { Expression expected = Sequence(