diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 41ad49e..3e6994a 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -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 { diff --git a/compiler/parser/parser.go b/compiler/parser/parser.go index 93f04f7..469f333 100644 --- a/compiler/parser/parser.go +++ b/compiler/parser/parser.go @@ -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 { diff --git a/script/script.go b/script/script.go index 0b81027..d084551 100644 --- a/script/script.go +++ b/script/script.go @@ -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)