commit c748daa8f73ecc713a24e665e72c06e36d123d46
parent d6a03141321e3a1ea18510d2427a0255ef238423
Author: lash <dev@holbrook.no>
Date: Thu, 6 Apr 2023 08:49:16 +0100
Make assembler handle non-DOWN menu choices
Diffstat:
5 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/go/asm/asm.go b/go/asm/asm.go
@@ -328,13 +328,20 @@ func(bt *Batcher) MenuExit(w io.Writer) (int, error) {
func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
bt.inMenu = true
var selector string
+ var sym string
if arg.Size != nil {
selector = strconv.FormatUint(uint64(*arg.Size), 10)
} else if arg.Selector != nil {
selector = *arg.Selector
}
- log.Printf("menu processor add %v '%v' '%v' '%v'", code, *arg.Sym, selector, *arg.Desc)
- err := bt.menuProcessor.Add(code, *arg.Sym, selector, *arg.Desc)
+
+ if selector == "" {
+ selector = *arg.Sym
+ } else if arg.Sym != nil {
+ sym = *arg.Sym
+ }
+ log.Printf("menu processor add %v '%v' '%v' '%v'", code, selector, *arg.Desc, sym)
+ err := bt.menuProcessor.Add(code, selector, *arg.Desc, sym)
return 0, err
}
diff --git a/go/asm/asm_test.go b/go/asm/asm_test.go
@@ -94,7 +94,7 @@ func TestParseDouble(t *testing.T) {
func TestParseMenu(t *testing.T) {
s := `DOWN foobar 00 "inky pinky"
-UP bazbar s1 "tinkywinky"
+UP s1 "tinkywinky"
`
r := bytes.NewBuffer(nil)
n, err := Parse(s, r)
diff --git a/go/asm/menu.go b/go/asm/menu.go
@@ -48,6 +48,9 @@ func(mp *MenuProcessor) Add(bop string, choice string, display string, target st
if bopCode == 0 {
return fmt.Errorf("unknown menu instruction: %v", bop)
}
+ if len(target) > 0 && bopCode != MENU_DOWN {
+ return fmt.Errorf("target is only valid for DOWN")
+ }
m := menuItem{
code: bopCode,
choice: choice,
diff --git a/go/asm/menu_test.go b/go/asm/menu_test.go
@@ -13,15 +13,15 @@ func TestMenuInterpreter(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- err = m.Add("NEXT", "1", "pinky", "bar")
+ err = m.Add("NEXT", "1", "pinky", "")
if err != nil {
t.Fatal(err)
}
- err = m.Add("PREVIOUS", "2", "blinky clyde", "baz")
+ err = m.Add("PREVIOUS", "2", "blinky clyde", "")
if err != nil {
t.Fatal(err)
}
- err = m.Add("UP", "99", "tinky-winky", "xyzzy")
+ err = m.Add("UP", "99", "tinky-winky", "")
if err != nil {
t.Fatal(err)
}
diff --git a/go/testdata/foo.fst b/go/testdata/foo.fst
@@ -6,3 +6,4 @@ INCMP 1 _
INCMP 2 baz
CATCH _catch 1 1
DOWN foofoo 1 "go to foo"
+UP 2 "up go go go"