Catch browse back beyond start
This commit is contained in:
parent
4da19b3047
commit
719368301b
@ -6,6 +6,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IndexError struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func(err *IndexError) Error() string {
|
||||||
|
return fmt.Sprintf("already at first index")
|
||||||
|
}
|
||||||
|
|
||||||
// State holds the command stack, error condition of a unique execution session.
|
// State holds the command stack, error condition of a unique execution session.
|
||||||
//
|
//
|
||||||
// It also holds cached values for all results of executed symbols.
|
// It also holds cached values for all results of executed symbols.
|
||||||
@ -208,7 +215,7 @@ func(st *State) Previous() (uint16, error) {
|
|||||||
return 0, fmt.Errorf("state root node not yet defined")
|
return 0, fmt.Errorf("state root node not yet defined")
|
||||||
}
|
}
|
||||||
if st.sizeIdx == 0 {
|
if st.sizeIdx == 0 {
|
||||||
return 0, fmt.Errorf("already at first index")
|
return 0, &IndexError{} // ("already at first index")
|
||||||
}
|
}
|
||||||
st.sizeIdx -= 1
|
st.sizeIdx -= 1
|
||||||
s, idx := st.Where()
|
s, idx := st.Where()
|
||||||
|
@ -313,7 +313,18 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx)
|
target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx)
|
||||||
if err != nil {
|
_, ok := err.(*state.IndexError)
|
||||||
|
if ok {
|
||||||
|
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_, err = vm.st.SetFlag(state.FLAG_READIN)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
} else if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
vm.Reset()
|
vm.Reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user