module FileLocation
( err, err', undef, fromJst, fromRht, indx, indxShow
, debug, debugM, debugMsg, debugMsgIf, dbg, dbgMsg, trc, ltrace, ltraceM, strace
, locationToString
, thrwIO, thrwsIO
)
where
import FileLocation.LocationString (locationToString)
import Debug.FileLocation (debug, debugM, debugMsg, dbg, dbgMsg, trc, ltrace, ltraceM, strace)
import Debug.Util (debugMsgIf)
import Control.Exception.FileLocation (thrwIO, thrwsIO)
import Debug.Trace (trace)
import Language.Haskell.TH.Syntax
import Language.Haskell.TH(varE)
import Data.Maybe(fromMaybe)
import qualified Data.Map as M (lookup)
err :: String -> Q Exp
err str = do
loc <- qLocation
let prefix = (locationToString loc) ++ " "
[|error (prefix ++ str)|]
err' :: Q Exp
err' = do
loc <- qLocation
let prefix = (locationToString loc) ++ " "
[| error . (prefix ++) |]
undef :: Q Exp
undef = do
loc <- qLocation
let prefix = (locationToString loc) ++ " "
[|trace (prefix ++ "undefined") undefined|]
fromJst :: Q Exp
fromJst = do
loc <- qLocation
let msg = (locationToString loc) ++ " fromJst: Nothing"
[|\_m -> case _m of
Just _v -> _v
Nothing -> error msg|]
fromRht :: Q Exp
fromRht = do
loc <- qLocation
let msg = (locationToString loc) ++ " fromRht: Left: "
[|\_m -> case _m of
Right _v -> _v
Left _e -> error (msg ++ show _e)|]
indx :: Q Exp
indx = indx_common False
indxShow :: Q Exp
indxShow = indx_common True
indx_common :: Bool -> Q Exp
indx_common = indxWith_common [| M.lookup |]
indxWith_common :: Q Exp -> Bool -> Q Exp
indxWith_common lookupE showElt = do
loc <- qLocation
let msg = (locationToString loc) ++ " indx: Element not in the map"
msgE varName = if showElt
then [| msg ++ ": " ++ show $(varE varName) |]
else [| msg |]
[| \_x _m -> fromMaybe (error $(msgE '_x)) ($(lookupE) _x _m) |]