Skip to content

Commit

Permalink
Fixed precedence of logical operators (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex authored Dec 9, 2021
1 parent f7f17ea commit 07e3358
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 70 deletions.
14 changes: 14 additions & 0 deletions pkg/compiler/compiler_ternary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ func TestTernaryOperator(t *testing.T) {
So(string(out), ShouldEqual, `["no value",2,4,6]`)
}
})

Convey("Multi expression", t, func() {
out := compiler.New().MustCompile(`
RETURN 0 && true ? "1" : "some"
`).MustRun(context.Background())

So(string(out), ShouldEqual, `"some"`)

out = compiler.New().MustCompile(`
RETURN length([]) > 0 && true ? "1" : "some"
`).MustRun(context.Background())

So(string(out), ShouldEqual, `"some"`)
})
}

func BenchmarkTernaryOperator(b *testing.B) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/antlr/FqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ rangeOperand

expression
: unaryOperator right=expression
| condition=expression ternaryOperator=QuestionMark onTrue=expression? Colon onFalse=expression
| left=expression logicalAndOperator right=expression
| left=expression logicalOrOperator right=expression
| condition=expression ternaryOperator=QuestionMark onTrue=expression? Colon onFalse=expression
| predicate
;

Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/fql/FqlParser.interp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/parser/fql/fql_lexer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07e3358

Please sign in to comment.