mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Encapsulate throwing failures.
This commit is contained in:
parent
a8853d9807
commit
64d8aced70
@ -93,7 +93,7 @@ runMyersStep eq state step = let ?callStack = popCallStack callStack in case ste
|
|||||||
|
|
||||||
|
|
||||||
decompose :: HasCallStack => MyersF a b c -> Myers a b c
|
decompose :: HasCallStack => MyersF a b c -> Myers a b c
|
||||||
decompose myers = let ?callStack = fromCallSiteList (filter ((/= "M") . fst) (getCallStack (popCallStack callStack))) in case myers of
|
decompose myers = let ?callStack = popCallStack callStack in case myers of
|
||||||
LCS graph
|
LCS graph
|
||||||
| null as || null bs -> return []
|
| null as || null bs -> return []
|
||||||
| otherwise -> do
|
| otherwise -> do
|
||||||
@ -145,9 +145,9 @@ decompose myers = let ?callStack = fromCallSiteList (filter ((/= "M") . fst) (ge
|
|||||||
v <- gets (stateFor direction)
|
v <- gets (stateFor direction)
|
||||||
let i = index v k
|
let i = index v k
|
||||||
if i < 0 then
|
if i < 0 then
|
||||||
throw (MyersException ("negative index " <> Prologue.show i) callStack)
|
fail ("negative index " <> Prologue.show i)
|
||||||
else if i >= length v then
|
else if i >= length v then
|
||||||
throw (MyersException ("index " <> Prologue.show i <> "past end of state vector " <> Prologue.show (length v)) callStack)
|
fail ("index " <> Prologue.show i <> "past end of state vector " <> Prologue.show (length v))
|
||||||
else
|
else
|
||||||
return (v Vector.! i)
|
return (v Vector.! i)
|
||||||
|
|
||||||
@ -199,6 +199,10 @@ decompose myers = let ?callStack = fromCallSiteList (filter ((/= "M") . fst) (ge
|
|||||||
Forward -> return (here, there)
|
Forward -> return (here, there)
|
||||||
Reverse -> return (there, here)
|
Reverse -> return (there, here)
|
||||||
|
|
||||||
|
fail :: (HasCallStack, Monad m) => String -> m a
|
||||||
|
fail s = let ?callStack = fromCallSiteList (filter ((/= "M") . fst) (getCallStack callStack)) in
|
||||||
|
throw (MyersException s callStack)
|
||||||
|
|
||||||
invert Forward = Reverse
|
invert Forward = Reverse
|
||||||
invert Reverse = Forward
|
invert Reverse = Forward
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user