move int parsing to after word check

This commit is contained in:
David 2021-02-20 19:22:36 -05:00
parent ff5346994f
commit 0676cad34d

17
eval.go
View File

@ -46,17 +46,10 @@ func (c *Context) Eval(line string) error {
ifcheck, _ := c.IfStack.Pick(0) ifcheck, _ := c.IfStack.Pick(0)
if len(c.IfStack.values) == 0 || (len(c.IfStack.values) > 0 && ifcheck == 1) || w.BranchCheck { if len(c.IfStack.values) == 0 || (len(c.IfStack.values) > 0 && ifcheck == 1) || w.BranchCheck {
int, err := strconv.Atoi(sword)
if err == nil {
// it was a number! put it on the stack.
c.Stack.Push(int)
word = []byte{}
continue
}
// run word // run word
c.RStack.Push(i) c.RStack.Push(i)
if err = c.Exec(w); err != nil { err := c.Exec(w)
if err != nil {
return err return err
} }
i, err = c.RStack.Pop() i, err = c.RStack.Pop()
@ -87,8 +80,14 @@ func (c *Context) Exec(w Word) error {
if err != nil { if err != nil {
return err return err
} }
} else {
it, err := strconv.Atoi(w.Name)
if err == nil {
// it was a number! put it on the stack.
c.Stack.Push(it)
} else { } else {
return fmt.Errorf("unable to parse word %s", w.Name) return fmt.Errorf("unable to parse word %s", w.Name)
} }
}
return nil return nil
} }