parser.ParseFile removed (#117)

* parser.ParseFile removed

* return values
This commit is contained in:
earncef 2019-02-26 07:52:08 +01:00 committed by Daniel
parent 6ec360c8b7
commit 5816186821
6 changed files with 16 additions and 36 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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