qrz/vendor/github.com/gobuffalo/packr/v2/jam/parser/gogen.go
Paul Lecuq 36c5d6f2ed
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
large change on qrz
- web service with json support
- web page
- cron service to update database infos
2020-05-09 19:09:27 +02:00

44 lines
767 B
Go

package parser
import (
"go/ast"
"go/parser"
"go/token"
"io"
"strings"
"github.com/gobuffalo/packd"
"github.com/markbates/errx"
)
// ParsedFile ...
type ParsedFile struct {
File packd.SimpleFile
FileSet *token.FileSet
Ast *ast.File
Lines []string
}
// ParseFileMode ...
func ParseFileMode(gf packd.SimpleFile, mode parser.Mode) (ParsedFile, error) {
pf := ParsedFile{
FileSet: token.NewFileSet(),
File: gf,
}
src := gf.String()
f, err := parser.ParseFile(pf.FileSet, gf.Name(), src, mode)
if err != nil && errx.Unwrap(err) != io.EOF {
return pf, err
}
pf.Ast = f
pf.Lines = strings.Split(src, "\n")
return pf, nil
}
// ParseFile ...
func ParseFile(gf packd.SimpleFile) (ParsedFile, error) {
return ParseFileMode(gf, 0)
}