summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5/tengo/compiler/parser/parse_file.go
blob: 0482c775e28743c983a11284fe5411a64bf30126 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
}