Skip to content

Commit

Permalink
bugfix: parse expect error when mis match braces (#421)
Browse files Browse the repository at this point in the history
* bugfix: parse expect error when mis match braces

Change-Id: Iba1ad456d5b020375bb0416f44fb54bc2e346d62

* fix wrong test case in vm_test

Change-Id: Idcdaf7ecc93eb61d374249d11282b8286557d30d

---------

Co-authored-by: lihongyuan <[email protected]>
  • Loading branch information
sailinglawliet and lihongyuan authored Apr 23, 2023
1 parent 82b543f commit f90bc00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (p *Parser) ParseFile() (file *File, err error) {
}

stmts := p.parseStmtList()
p.expect(token.EOF)
if p.errors.Len() > 0 {
return nil, p.errors.Err()
}
Expand Down
14 changes: 14 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,20 @@ func TestParseFloat(t *testing.T) {
}
}

func TestMismatchBrace(t *testing.T) {
expectParseError(t, `
fmt := import("fmt")
out := 0
if 3 == 1 {
out = 1
}
} else {
out = 2
}
fmt.println(out)
`)
}

func TestParseNumberExpressions(t *testing.T) {
expectParse(t, `0x15e+2`, func(p pfn) []Stmt {
return stmts(
Expand Down
4 changes: 2 additions & 2 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2754,10 +2754,10 @@ export func(a) {
Opts().Module("mod0", `if 1 { } else { export true }`),
tengo.UndefinedValue)
expectRun(t, `out = import("mod0")`,
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { export true } } }`),
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { export true } }`),
true)
expectRun(t, `out = import("mod0")`,
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { break } } }`),
Opts().Module("mod0", `for v:=0;;v++ { if v == 3 { break } }`),
tengo.UndefinedValue)

// duplicate compiled functions
Expand Down

0 comments on commit f90bc00

Please sign in to comment.