Skip to content

Commit

Permalink
parser: check not found Go+ class by composite gox
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Aug 23, 2023
1 parent c7d5637 commit b043e47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cl/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (p *gmxSettings) getScheds(cb *gox.CodeBuilder) []goast.Stmt {
}

func newGmx(ctx *pkgCtx, pkg *gox.Package, file string, conf *Config) *gmxSettings {
ext := parser.ClassFileExt(file)
ext, _ := parser.ClassFileExt(file)
gt, ok := conf.LookupClass(ext)
if !ok {
panic("TODO: class not found")
Expand Down
11 changes: 7 additions & 4 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,11 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
}
if ctx.gmxSettings == nil {
for file, gmx := range files {
if gmx.IsClass && parser.ClassFileExt(file) != ".gox" {
ctx.gmxSettings = newGmx(ctx, p, file, conf)
break
if gmx.IsClass {
if ext, _ := parser.ClassFileExt(file); ext != ".gox" {
ctx.gmxSettings = newGmx(ctx, p, file, conf)
break
}
}
}
}
Expand Down Expand Up @@ -560,7 +562,8 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
case f.IsClass:
classType = getDefaultClass(file)
if parent.gmxSettings != nil {
o, ok := parent.sprite[parser.ClassFileExt(file)]
ext, _ := parser.ClassFileExt(file)
o, ok := parent.sprite[ext]
if ok {
baseTypeName, baseType, spxClass = o.Name(), o.Type(), true
}
Expand Down
14 changes: 9 additions & 5 deletions parser/parser_gop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package parser
import (
"bytes"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
Expand Down Expand Up @@ -115,14 +116,14 @@ func ParseDirEx(fset *token.FileSet, path string, conf Config) (pkgs map[string]
}

// ClassFileExt returns the classfile extension
func ClassFileExt(path string) string {
ext := filepath.Ext(path)
func ClassFileExt(path string) (ext string, compositeGox bool) {
ext = filepath.Ext(path)
if ext == ".gox" {
if c := filepath.Ext(path[:len(path)-4]); c != "" {
return c
return c, true
}
}
return ext
return
}

// ParseFSDir calls ParseFile for all files with names ending in ".gop" in the
Expand Down Expand Up @@ -151,7 +152,7 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, conf Config) (p
continue
}
fname := d.Name()
ext := ClassFileExt(fname)
ext, compositeGox := ClassFileExt(fname)
var isProj, isClass, useGoParser bool
switch ext {
case ".gop":
Expand All @@ -164,6 +165,9 @@ func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, conf Config) (p
isClass = true
default:
if isProj, isClass = conf.IsClass(ext); !isClass {
if compositeGox {
return nil, fmt.Errorf("not found Go+ class by ext %q for %q", ext, fname)
}
continue
}
}
Expand Down

0 comments on commit b043e47

Please sign in to comment.