Fixed panic when bailout is triggered in parser.ParseFile() (#113)
* Fixed panic when bailout is triggered in parser.ParseFile() * Removed redundant "parse error" prefix for parse errors.
This commit is contained in:
parent
6dd573c3f6
commit
6ec360c8b7
3 changed files with 33 additions and 4 deletions
|
@ -875,6 +875,22 @@ func() {
|
|||
intObject(1))))
|
||||
|
||||
expectError(t, `import("user1")`, "no such file or directory") // unknown module name
|
||||
|
||||
expectError(t, `
|
||||
r["x"] = {
|
||||
"a":1,
|
||||
"b":1,
|
||||
"c":1,
|
||||
"d":1,
|
||||
"e":1,
|
||||
"f":1,
|
||||
"g":1,
|
||||
"h":1,
|
||||
"i":1,
|
||||
"j":1,
|
||||
"k":1,
|
||||
}
|
||||
`, "Parse Error: expected 'IDENT', found \"a\"\n\tat test:3:5 (and 10 more errors)") // too many errors
|
||||
}
|
||||
|
||||
func concat(instructions ...[]byte) []byte {
|
||||
|
|
|
@ -57,7 +57,18 @@ func NewParser(file *source.File, src []byte, trace io.Writer) *Parser {
|
|||
}
|
||||
|
||||
// ParseFile parses the source and returns an AST file unit.
|
||||
func (p *Parser) ParseFile() (*ast.File, error) {
|
||||
func (p *Parser) ParseFile() (file *ast.File, err error) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
if _, ok := e.(bailout); !ok {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
p.errors.Sort()
|
||||
err = p.errors.Err()
|
||||
}()
|
||||
|
||||
if p.trace {
|
||||
defer un(trace(p, "File"))
|
||||
}
|
||||
|
@ -71,10 +82,12 @@ func (p *Parser) ParseFile() (*ast.File, error) {
|
|||
return nil, p.errors.Err()
|
||||
}
|
||||
|
||||
return &ast.File{
|
||||
file = &ast.File{
|
||||
InputFile: p.file,
|
||||
Stmts: stmts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Parser) parseExpr() ast.Expr {
|
||||
|
|
|
@ -92,7 +92,7 @@ func (s *Script) Compile() (*Compiled, error) {
|
|||
p := parser.NewParser(srcFile, s.input, nil)
|
||||
file, err := p.ParseFile()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse error: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := compiler.NewCompiler(srcFile, symbolTable, nil, stdModules, nil)
|
||||
|
|
Loading…
Reference in a new issue