Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit c9cb9f3

Browse files
authored
Merge pull request #66 from ciobis/fix-boolean-negation
Fix parsing for boolean expressions starting with negation
2 parents f119644 + 93701c6 commit c9cb9f3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ expression
77
| expression bracketSpecifier # bracketedExpression
88
| bracketSpecifier # bracketExpression
99
| expression COMPARATOR expression # comparisonExpression
10+
| '!' expression # notExpression
1011
| expression '&&' expression # andExpression
1112
| expression '||' expression # orExpression
1213
| identifier # identifierExpression
13-
| '!' expression # notExpression
1414
| '(' expression ')' # parenExpression
1515
| wildcard # wildcardExpression
1616
| multiSelectList # multiSelectListExpression

jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,32 @@ public void bareNegatedExpression() {
805805
assertThat(actual, is(expected));
806806
}
807807

808+
@Test
809+
public void negatedBooleansTripleConjunctionExpression() {
810+
Expression<Object> expected = And(
811+
And(
812+
Negate(Property("foo")),
813+
Negate(Property("bar"))
814+
),
815+
Negate(Property("buzz"))
816+
);
817+
Expression<Object> actual = compile("!foo && !bar && !buzz");
818+
assertThat(actual, is(expected));
819+
}
820+
821+
@Test
822+
public void negatedBooleansTripleDisjunctionExpression() {
823+
Expression<Object> expected = Or(
824+
Or(
825+
Negate(Property("foo")),
826+
Negate(Property("bar"))
827+
),
828+
Negate(Property("buzz"))
829+
);
830+
Expression<Object> actual = compile("!foo || !bar || !buzz");
831+
assertThat(actual, is(expected));
832+
}
833+
808834
@Test
809835
public void negatedSelectionExpression() {
810836
Expression<Object> expected = Sequence(

0 commit comments

Comments
 (0)