Make assembler handle non-DOWN menu choices
This commit is contained in:
parent
d6a0314132
commit
c748daa8f7
@ -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) {
|
func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
|
||||||
bt.inMenu = true
|
bt.inMenu = true
|
||||||
var selector string
|
var selector string
|
||||||
|
var sym string
|
||||||
if arg.Size != nil {
|
if arg.Size != nil {
|
||||||
selector = strconv.FormatUint(uint64(*arg.Size), 10)
|
selector = strconv.FormatUint(uint64(*arg.Size), 10)
|
||||||
} else if arg.Selector != nil {
|
} else if arg.Selector != nil {
|
||||||
selector = *arg.Selector
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func TestParseDouble(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMenu(t *testing.T) {
|
func TestParseMenu(t *testing.T) {
|
||||||
s := `DOWN foobar 00 "inky pinky"
|
s := `DOWN foobar 00 "inky pinky"
|
||||||
UP bazbar s1 "tinkywinky"
|
UP s1 "tinkywinky"
|
||||||
`
|
`
|
||||||
r := bytes.NewBuffer(nil)
|
r := bytes.NewBuffer(nil)
|
||||||
n, err := Parse(s, r)
|
n, err := Parse(s, r)
|
||||||
|
@ -48,6 +48,9 @@ func(mp *MenuProcessor) Add(bop string, choice string, display string, target st
|
|||||||
if bopCode == 0 {
|
if bopCode == 0 {
|
||||||
return fmt.Errorf("unknown menu instruction: %v", bop)
|
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{
|
m := menuItem{
|
||||||
code: bopCode,
|
code: bopCode,
|
||||||
choice: choice,
|
choice: choice,
|
||||||
|
@ -13,15 +13,15 @@ func TestMenuInterpreter(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = m.Add("NEXT", "1", "pinky", "bar")
|
err = m.Add("NEXT", "1", "pinky", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = m.Add("PREVIOUS", "2", "blinky clyde", "baz")
|
err = m.Add("PREVIOUS", "2", "blinky clyde", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = m.Add("UP", "99", "tinky-winky", "xyzzy")
|
err = m.Add("UP", "99", "tinky-winky", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
1
go/testdata/foo.fst
vendored
1
go/testdata/foo.fst
vendored
@ -6,3 +6,4 @@ INCMP 1 _
|
|||||||
INCMP 2 baz
|
INCMP 2 baz
|
||||||
CATCH _catch 1 1
|
CATCH _catch 1 1
|
||||||
DOWN foofoo 1 "go to foo"
|
DOWN foofoo 1 "go to foo"
|
||||||
|
UP 2 "up go go go"
|
||||||
|
Loading…
Reference in New Issue
Block a user