Skip to content

Commit

Permalink
ParseFSDir: support .spx .gmx
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Aug 22, 2021
1 parent f7ab9b8 commit 44335d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/gengo/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
PkgFlagGoGen
PkgFlagGopModified
PkgFlagSpx
PkgFlagGmx
)

const (
Expand Down Expand Up @@ -123,7 +124,7 @@ func (p *Runner) GenGo(dir string, recursive bool, base *cl.Config) {
if (pkgFlags & PkgFlagGo) != 0 { // a Go package
// TODO: depency check
} else if gopTime.After(gogenTime) { // update a Go+ package
fmt.Printf("GenGoPkg %s ...\n", dir)
fmt.Printf("GenGoPkg %s\n", dir)
pkgFlags |= PkgFlagGopModified
p.GenGoPkg(dir, base)
}
Expand All @@ -139,6 +140,7 @@ var (
extPkgFlags = map[string]int{
".gop": PkgFlagGoPlus,
".spx": PkgFlagSpx,
".gmx": PkgFlagGmx,
".go": PkgFlagGo,
}
)
Expand Down
12 changes: 11 additions & 1 deletion parser/parser_gop.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, filter func(os.
continue
}
fname := d.Name()
if strings.HasSuffix(fname, ".gop") && !strings.HasPrefix(fname, "_") && (filter == nil || filter(d)) {
ext := filepath.Ext(fname)
_, isGop := extGopFiles[ext]
if isGop && !strings.HasPrefix(fname, "_") && (filter == nil || filter(d)) {
filename := fs.Join(path, fname)
if filedata, err := fs.ReadFile(filename); err == nil {
if src, err := ParseFSFile(fset, fs, filename, filedata, mode); err == nil {
Expand All @@ -151,6 +153,14 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, filter func(os.
return
}

var (
extGopFiles = map[string]struct{}{
".gop": {},
".spx": {},
".gmx": {},
}
)

// -----------------------------------------------------------------------------

// ParseFile parses the source code of a single Go+ source file and returns the corresponding ast.File node.
Expand Down

0 comments on commit 44335d9

Please sign in to comment.