Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv ClassFileExt: parser => cl #1530

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ func getGoxConf() *gox.Config {
return &gox.Config{Fset: fset, Importer: imp}
}

func TestExt(t *testing.T) {
cases := [][2]string{
{"t.spx.gox", ".spx"},
{"t.spx", ".spx"},
{"t.gox", ".gox"},
{"t.abc", ".abc"},
}
for _, c := range cases {
if ret := ClassFileExt(c[0]); ret != c[1] {
t.Fatal("ClassFileExt:", c[0], "expected:", c[1], "got:", ret)
}
}
}

func TestErrMultiStarRecv(t *testing.T) {
defer func() {
if e := recover(); e == nil {
Expand Down
16 changes: 14 additions & 2 deletions cl/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"

"github.com/goplus/gop/ast"
"github.com/goplus/gop/parser"
"github.com/goplus/gop/token"
"github.com/goplus/gox"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func (p *gmxSettings) getScheds(cb *gox.CodeBuilder) []goast.Stmt {
}

func newGmx(ctx *pkgCtx, pkg *gox.Package, file string, f *ast.File, conf *Config) *gmxSettings {
ext := parser.ClassFileExt(file)
ext := ClassFileExt(file)
gt, ok := conf.LookupClass(ext)
if !ok {
panic("TODO: class not found")
Expand Down Expand Up @@ -177,3 +176,16 @@ func gmxMainFunc(p *gox.Package, ctx *pkgCtx) {
}

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

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

// -----------------------------------------------------------------------------
3 changes: 1 addition & 2 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/goplus/gop/ast"
"github.com/goplus/gop/ast/fromgo"
"github.com/goplus/gop/parser"
"github.com/goplus/gop/token"
"github.com/goplus/gox"
"github.com/goplus/gox/cpackages"
Expand Down Expand Up @@ -710,7 +709,7 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
case f.IsClass:
classType = getDefaultClass(file)
if parent.gmxSettings != nil {
ext := parser.ClassFileExt(file)
ext := ClassFileExt(file)
o, ok := parent.sprite[ext]
if ok {
baseTypeName, baseType, spxClass = o.Name(), o.Type(), true
Expand Down
32 changes: 0 additions & 32 deletions parser/classfile.go

This file was deleted.

14 changes: 0 additions & 14 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ func TestAssert(t *testing.T) {
assert(false, "panic msg")
}

func TestExt(t *testing.T) {
cases := [][2]string{
{"t.spx.gox", ".spx"},
{"t.spx", ".spx"},
{"t.gox", ".gox"},
{"t.abc", ".abc"},
}
for _, c := range cases {
if ret := ClassFileExt(c[0]); ret != c[1] {
t.Fatal("ClassFileExt:", c[0], "expected:", c[1], "got:", ret)
}
}
}

func panicMsg(e interface{}) string {
switch v := e.(type) {
case string:
Expand Down