bugfix: parse expect error when mis match braces ()

* 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 <lihongyuan.adrian@bytedance.com>
This commit is contained in:
Adrian Lee 2023-04-23 14:37:59 +08:00 committed by GitHub
parent 82b543fd98
commit f90bc00af2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View file

@ -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()
}

View file

@ -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(

View file

@ -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