Skip to content

Commit

Permalink
Fix parsing of pointers in nested closures
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed May 15, 2020
1 parent 337130d commit 022271e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,17 @@ func TestIssue105(t *testing.T) {
require.Contains(t, err.Error(), "ambiguous identifier Field")
}

func TestIssue_nested_closures(t *testing.T) {
code := `all(1..3, { all(1..3, { # > 0 }) and # > 0 })`

program, err := expr.Compile(code)
require.NoError(t, err)

output, err := expr.Run(program, nil)
require.NoError(t, err)
require.True(t, output.(bool))
}

//
// Mock types
//
Expand Down
8 changes: 4 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type parser struct {
current Token
pos int
err *file.Error
closure bool
depth int // closure call depth
}

type Tree struct {
Expand Down Expand Up @@ -219,7 +219,7 @@ func (p *parser) parsePrimary() Node {
return p.parsePostfixExpression(expr)
}

if p.closure {
if p.depth > 0 {
if token.Is(Operator, "#") || token.Is(Operator, ".") {
if token.Is(Operator, "#") {
p.next()
Expand Down Expand Up @@ -377,9 +377,9 @@ func (p *parser) parseClosure() Node {
token := p.current
p.expect(Bracket, "{")

p.closure = true
p.depth++
node := p.parseExpression(0)
p.closure = false
p.depth--

p.expect(Bracket, "}")
closure := &ClosureNode{
Expand Down

0 comments on commit 022271e

Please sign in to comment.