From 5816186821c3d4098175441f8616db115fa3e0c9 Mon Sep 17 00:00:00 2001 From: earncef Date: Tue, 26 Feb 2019 07:52:08 +0100 Subject: [PATCH] parser.ParseFile removed (#117) * parser.ParseFile removed * return values --- cmd/bench/main.go | 3 ++- cmd/tengo/main.go | 3 ++- compiler/parser/parse_file.go | 28 ---------------------------- compiler/parser/parse_source.go | 3 ++- compiler/parser/parser_test.go | 12 ++++++++---- runtime/vm_test.go | 3 ++- 6 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 compiler/parser/parse_file.go diff --git a/cmd/bench/main.go b/cmd/bench/main.go index c131f38..b546f0f 100644 --- a/cmd/bench/main.go +++ b/cmd/bench/main.go @@ -179,7 +179,8 @@ func parse(input []byte) (time.Duration, *ast.File, error) { start := time.Now() - file, err := parser.ParseFile(inputFile, input, nil) + p := parser.NewParser(inputFile, input, nil) + file, err := p.ParseFile() if err != nil { return time.Since(start), nil, err } diff --git a/cmd/tengo/main.go b/cmd/tengo/main.go index 470c687..635a204 100644 --- a/cmd/tengo/main.go +++ b/cmd/tengo/main.go @@ -199,7 +199,8 @@ func runREPL(in io.Reader, out io.Writer) { line := stdin.Text() srcFile := fileSet.AddFile("repl", -1, len(line)) - file, err := parser.ParseFile(srcFile, []byte(line), nil) + p := parser.NewParser(srcFile, []byte(line), nil) + file, err := p.ParseFile() if err != nil { _, _ = fmt.Fprintln(out, err.Error()) continue diff --git a/compiler/parser/parse_file.go b/compiler/parser/parse_file.go deleted file mode 100644 index 0482c77..0000000 --- a/compiler/parser/parse_file.go +++ /dev/null @@ -1,28 +0,0 @@ -package parser - -import ( - "io" - - "github.com/d5/tengo/compiler/ast" - "github.com/d5/tengo/compiler/source" -) - -// ParseFile parses a file with a given src. -func ParseFile(file *source.File, src []byte, trace io.Writer) (res *ast.File, err error) { - p := NewParser(file, src, trace) - - defer func() { - if e := recover(); e != nil { - if _, ok := e.(bailout); !ok { - panic(e) - } - } - - p.errors.Sort() - err = p.errors.Err() - }() - - res, err = p.ParseFile() - - return -} diff --git a/compiler/parser/parse_source.go b/compiler/parser/parse_source.go index 5d242db..5c71436 100644 --- a/compiler/parser/parse_source.go +++ b/compiler/parser/parse_source.go @@ -12,5 +12,6 @@ func ParseSource(filename string, src []byte, trace io.Writer) (res *ast.File, e fileSet := source.NewFileSet() file := fileSet.AddFile(filename, -1, len(src)) - return ParseFile(file, src, trace) + p := NewParser(file, src, trace) + return p.ParseFile() } diff --git a/compiler/parser/parser_test.go b/compiler/parser/parser_test.go index 356a396..1bbdc51 100644 --- a/compiler/parser/parser_test.go +++ b/compiler/parser/parser_test.go @@ -42,7 +42,8 @@ func expect(t *testing.T, input string, fn expectedFn) (ok bool) { if !ok { // print trace tr := &tracer{} - actual, _ := parser.ParseFile(testFile, []byte(input), tr) + p := parser.NewParser(testFile, []byte(input), tr) + actual, _ := p.ParseFile() if actual != nil { t.Logf("Parsed:\n%s", actual.String()) } @@ -50,7 +51,8 @@ func expect(t *testing.T, input string, fn expectedFn) (ok bool) { } }() - actual, err := parser.ParseFile(testFile, []byte(input), nil) + p := parser.NewParser(testFile, []byte(input), nil) + actual, err := p.ParseFile() if !assert.NoError(t, err) { return } @@ -82,12 +84,14 @@ func expectError(t *testing.T, input string) (ok bool) { if !ok { // print trace tr := &tracer{} - _, _ = parser.ParseFile(testFile, []byte(input), tr) + p := parser.NewParser(testFile, []byte(input), tr) + _, _ = p.ParseFile() t.Logf("Trace:\n%s", strings.Join(tr.out, "")) } }() - _, err := parser.ParseFile(testFile, []byte(input), nil) + p := parser.NewParser(testFile, []byte(input), nil) + _, err := p.ParseFile() if !assert.Error(t, err) { return } diff --git a/runtime/vm_test.go b/runtime/vm_test.go index b11b4b6..b2aa19f 100644 --- a/runtime/vm_test.go +++ b/runtime/vm_test.go @@ -287,7 +287,8 @@ func parse(t *testing.T, input string) *ast.File { testFileSet := source.NewFileSet() testFile := testFileSet.AddFile("test", -1, len(input)) - file, err := parser.ParseFile(testFile, []byte(input), nil) + p := parser.NewParser(testFile, []byte(input), nil) + file, err := p.ParseFile() if !assert.NoError(t, err) { return nil }