Skip to content

Commit 62e5ee3

Browse files
committed
modfile: Class add Embedded (class [-embed] *.workExt WorkClass)
1 parent d2b6c84 commit 62e5ee3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

modfile/gop_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ go 1.17
7171
gop 1.1
7272
7373
project .gmx Game github.com/goplus/spx math
74-
class .spx Sprite
74+
class -embed .spx Sprite
7575
class .spx2 *Sprite2
7676
class .spx3 Sprite SpriteProto
7777
@@ -138,6 +138,9 @@ func TestParse1(t *testing.T) {
138138
if len(f.proj().Works) != 3 {
139139
t.Errorf("project workclass length expected be 3, but %d got", len(f.proj().Works))
140140
}
141+
if !f.proj().Works[0].Embedded {
142+
t.Error("project class[0].Embedded expected be true")
143+
}
141144
if f.proj().Works[0].Ext != ".spx" {
142145
t.Errorf("project class[0] exts expected be .spx, but %s got", f.proj().Works[0].Ext)
143146
}
@@ -269,10 +272,10 @@ gop 1.1 1.2
269272
doTestParseErr(t, `gop.mod:2: invalid gop version '1.x': must match format 1.23`, `
270273
gop 1.x
271274
`)
272-
doTestParseErr(t, `gop.mod:2: usage: project [*.projExt ProjClass] classFilePkgPath ...`, `
275+
doTestParseErr(t, `gop.mod:2: usage: project [*.projExt ProjectClass] classFilePkgPath ...`, `
273276
project
274277
`)
275-
doTestParseErr(t, `gop.mod:2: usage: project [*.projExt ProjClass] classFilePkgPath ...`, `
278+
doTestParseErr(t, `gop.mod:2: usage: project [*.projExt ProjectClass] classFilePkgPath ...`, `
276279
project .gmx Game
277280
`)
278281
doTestParseErr(t, `gop.mod:2: ext ." invalid: unquoted string cannot contain quote`, `
@@ -296,7 +299,7 @@ project "\?"
296299
doTestParseErr(t, `gop.mod:2: work class must declare after a project definition`, `
297300
class .spx Sprite
298301
`)
299-
doTestParseErr(t, `gop.mod:3: usage: class .workExt WorkClass [ProjClass]`, `
302+
doTestParseErr(t, `gop.mod:3: usage: class [-embed] *.workExt WorkClass [WorkPrototype]`, `
300303
project github.com/goplus/spx math
301304
class .spx
302305
`)

modfile/rule.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string
202202
f.Gop.Version = args[0]
203203
case "project":
204204
if len(args) < 1 {
205-
errorf("usage: project [*.projExt ProjClass] classFilePkgPath ...")
205+
errorf("usage: project [*.projExt ProjectClass] classFilePkgPath ...")
206206
return
207207
}
208208
if isExt(args[0], true) {
209209
if len(args) < 3 || strings.Contains(args[1], "/") {
210-
errorf("usage: project [*.projExt ProjClass] classFilePkgPath ...")
210+
errorf("usage: project [*.projExt ProjectClass] classFilePkgPath ...")
211211
return
212212
}
213213
ext, fullExt, err := parseExt(&args[0], true)
@@ -244,8 +244,13 @@ func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string
244244
errorf("work class must declare after a project definition")
245245
return
246246
}
247+
embedded := false
248+
if len(args) > 0 && args[0] == "-embed" {
249+
args = args[1:]
250+
embedded = true
251+
}
247252
if len(args) < 2 {
248-
errorf("usage: class .workExt WorkClass [ProjClass]")
253+
errorf("usage: class [-embed] *.workExt WorkClass [WorkPrototype]")
249254
return
250255
}
251256
workExt, fullExt, err := parseExt(&args[0], false)
@@ -267,11 +272,12 @@ func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string
267272
}
268273
}
269274
proj.Works = append(proj.Works, &Class{
270-
Ext: workExt,
271-
FullExt: fullExt,
272-
Class: class,
273-
Proto: protoClass,
274-
Syntax: line,
275+
Ext: workExt,
276+
FullExt: fullExt,
277+
Class: class,
278+
Proto: protoClass,
279+
Embedded: embedded,
280+
Syntax: line,
275281
})
276282
case "import":
277283
proj := f.proj()
@@ -336,7 +342,7 @@ var (
336342
symbolRE = regexp.MustCompile(`\*?[A-Z]\w*`)
337343
)
338344

339-
// TODO: to be optimized
345+
// TODO(xsw): to be optimized
340346
func parseSymbol(s *string) (t string, err error) {
341347
t, err = parseString(s)
342348
if err != nil {

0 commit comments

Comments
 (0)