diff --git a/parser/interface.go b/parser/interface.go index c4bf7c9e0..a0fd6bffd 100644 --- a/parser/interface.go +++ b/parser/interface.go @@ -42,9 +42,8 @@ const ( DeclarationErrors // AllErrors - report all errors (not just the first 10 on different lines) AllErrors - // ParseGoFilesByGo - parse Go files by go/parser, not gop/parser - // Result will save to gop/ast.Package.GoFiles - ParseGoFilesByGo + // ParseGoAsGoPlus - parse Go files by gop/parser + ParseGoAsGoPlus ) // ParseFile parses the source code of a single Go source file and returns diff --git a/parser/parser_gop.go b/parser/parser_gop.go index 1bb39699c..5b80f460b 100644 --- a/parser/parser_gop.go +++ b/parser/parser_gop.go @@ -151,7 +151,7 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, conf Config) (p if strings.HasPrefix(fname, "gop_autogen") { continue } - useGoParser = (conf.Mode & ParseGoFilesByGo) != 0 + useGoParser = (conf.Mode & ParseGoAsGoPlus) == 0 default: if isProj, isClass = conf.IsClass(ext); !isClass { continue @@ -161,7 +161,7 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, conf Config) (p filename := fs.Join(path, fname) if useGoParser { if filedata, err := fs.ReadFile(filename); err == nil { - if src, err := goparser.ParseFile(fset, filename, filedata, goparser.Mode(conf.Mode & ^ParseGoFilesByGo)); err == nil { + if src, err := goparser.ParseFile(fset, filename, filedata, goparser.Mode(conf.Mode)); err == nil { pkg := reqPkg(pkgs, src.Name.Name) if pkg.GoFiles == nil { pkg.GoFiles = make(map[string]*goast.File) diff --git a/parser/parserdir_test.go b/parser/parserdir_test.go index 503cb29c6..9fb0aa53a 100644 --- a/parser/parserdir_test.go +++ b/parser/parserdir_test.go @@ -90,7 +90,7 @@ func testFrom(t *testing.T, pkgDir, sel string, exclude Mode) { } log.Println("Parsing", pkgDir) fset := token.NewFileSet() - pkgs, err := ParseDir(fset, pkgDir, nil, (Trace|ParseComments)&^exclude) + pkgs, err := ParseDir(fset, pkgDir, nil, (Trace|ParseComments|ParseGoAsGoPlus)&^exclude) if err != nil || len(pkgs) != 1 { if errs, ok := err.(scanner.ErrorList); ok { for _, e := range errs { @@ -111,7 +111,7 @@ func testFrom(t *testing.T, pkgDir, sel string, exclude Mode) { func TestParseGo(t *testing.T) { fset := token.NewFileSet() - pkgs, err := ParseDirEx(fset, "./_testdata/functype", Config{Mode: Trace}) + pkgs, err := ParseDirEx(fset, "./_testdata/functype", Config{Mode: Trace | ParseGoAsGoPlus}) if err != nil { t.Fatal("TestParseGo: ParseDir failed -", err) } @@ -122,7 +122,7 @@ func TestParseGo(t *testing.T) { func TestParseGoFiles(t *testing.T) { fset := token.NewFileSet() - pkgs, err := ParseFiles(fset, []string{"./_testdata/functype/functype.go"}, Trace) + pkgs, err := ParseFiles(fset, []string{"./_testdata/functype/functype.go"}, Trace|ParseGoAsGoPlus) if err != nil { t.Fatal("TestParseGoFiles: ParseFiles failed -", err) } @@ -146,7 +146,7 @@ func TestGopAutoGen(t *testing.T) { func TestGoFile(t *testing.T) { fset := token.NewFileSet() fs := parsertest.NewSingleFileFS("/foo", "test.go", `package foo`) - pkgs, err := ParseFSDir(fset, fs, "/foo", Config{Mode: ParseGoFilesByGo}) + pkgs, err := ParseFSDir(fset, fs, "/foo", Config{}) if err != nil { t.Fatal("ParseFSDir:", err) } @@ -158,19 +158,19 @@ func TestGoFile(t *testing.T) { func TestErrParse(t *testing.T) { fset := token.NewFileSet() fs := parsertest.NewSingleFileFS("/foo", "test.go", `package foo bar`) - _, err := ParseFSDir(fset, fs, "/foo", Config{Mode: ParseGoFilesByGo}) + _, err := ParseFSDir(fset, fs, "/foo", Config{}) if err == nil { t.Fatal("ParseFSDir test.go: no error?") } fs = parsertest.NewSingleFileFS("/foo", "test.gop", `package foo bar`) - _, err = ParseFSDir(fset, fs, "/foo", Config{Mode: ParseGoFilesByGo}) + _, err = ParseFSDir(fset, fs, "/foo", Config{}) if err == nil { t.Fatal("ParseFSDir test.gop: no error?") } fs = parsertest.NewMemFS(map[string][]string{"/foo": {"test.go"}}, map[string]string{}) - _, err = ParseFSDir(fset, fs, "/foo", Config{Mode: ParseGoFilesByGo}) + _, err = ParseFSDir(fset, fs, "/foo", Config{}) if err != syscall.ENOENT { t.Fatal("ParseFSDir:", err) }