From 43a6d15777db8a8d60e19748b430b628a743ba9b Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Fri, 22 Dec 2017 11:44:05 -0500 Subject: [PATCH] fixed issue with and or precedence --- if_test.go | 8 ++++++++ parser/precedences.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/if_test.go b/if_test.go index 2e1c3cb..8b0c1b1 100644 --- a/if_test.go +++ b/if_test.go @@ -38,6 +38,14 @@ func Test_Render_If_And(t *testing.T) { r.Equal("", s) } +func Test_Render_If_And_True_True(t *testing.T) { + r := require.New(t) + input := `<%= if (2 == 2 && 1 == 1) { return "hi" } %>` + s, err := Render(input, NewContext()) + r.NoError(err) + r.Equal("hi", s) +} + func Test_Render_If_Or(t *testing.T) { r := require.New(t) input := `<%= if (false || true) { %>hi<%} %>` diff --git a/parser/precedences.go b/parser/precedences.go index fae387a..59a0a2a 100644 --- a/parser/precedences.go +++ b/parser/precedences.go @@ -18,6 +18,8 @@ var precedences = map[token.Type]int{ token.EQ: EQUALS, token.NOT_EQ: EQUALS, token.MATCHES: EQUALS, + token.AND: EQUALS, + token.OR: EQUALS, token.LT: LESSGREATER, token.LTEQ: LESSGREATER, token.GT: LESSGREATER, @@ -26,8 +28,6 @@ var precedences = map[token.Type]int{ token.MINUS: SUM, token.SLASH: PRODUCT, token.ASTERISK: PRODUCT, - token.AND: PRODUCT, - token.OR: PRODUCT, token.LPAREN: CALL, token.LBRACKET: INDEX, }