diff --git a/go/asm/asm.go b/go/asm/asm.go index fa75348..c3b5011 100644 --- 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 index 5365623..63dc98d 100644 --- 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 index 1f415ef..13a2c2d 100644 --- 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 index 426339d..8f0d7e7 100644 --- 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 index 83be4a0..cf418f9 100644 --- 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"