module Funcons.Exceptions where
import Funcons.Types
import Funcons.Printer
import Data.Text
type IException = (Funcons, Funcons, IE)
data IE = SortErr String
| Err String
| PartialOp String
| Internal String
| NoRule
| NoMoreBranches
| SideCondFail String
| InsufficientInput Name
| InsufficientInputConsumed Name
| PatternMismatch String
| StepOnValue [Values]
showIException :: IException -> String
showIException (f0,f,ie) = "Internal Exception: " ++ show ie ++ " on \n" ++ showFuncons f0
instance Show IE where
show (SortErr err) = "dynamic sort check (" ++ err ++ ")"
show NoRule = "no rule to execute"
show (Err err) = "exception (" ++ err ++ ")"
show (Internal err) = "exception (" ++ err ++ ")"
show (SideCondFail str) = str
show (PatternMismatch str) = str
show (InsufficientInput nm) = "insufficient supply for " ++ unpack nm
show (InsufficientInputConsumed nm) = "insufficient input consumed for entity " ++ unpack nm
show (PartialOp str) = "partial operation"
show (NoMoreBranches) = "no more branches to try"
show (StepOnValue v) = "attempting to step a value: " ++ showValuesSeq v
failsRule :: IException -> Bool
failsRule (_,_,SideCondFail _) = True
failsRule (_,_,PatternMismatch _) = True
failsRule (_,_,SortErr _) = True
failsRule (_,_,PartialOp _) = True
failsRule (_,_,StepOnValue _) = True
failsRule (_,_,NoMoreBranches) = True
failsRule (_,_,NoRule) = True
failsRule _ = False