Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Debug/Dump.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import qualified Internal.Parser as Parser

-- | This is the main `QuasiQuoter`.
dump :: QuasiQuoter
dump = QuasiQuoter {quoteExp = process}
dump = QuasiQuoter
{ quoteExp = process
, quoteType = \_ -> fl "use in types."
, quotePat = \_ -> fl "use in patterns."
, quoteDec = \_ -> fl "generating declarations."
}
where
fl m = fail $ "This quasiquoter is not for " ++ m

-- | Shorthand for `dump`.
d :: QuasiQuoter
Expand Down Expand Up @@ -61,7 +68,6 @@ process = id
.> joinAsColumns
.> (fmap (++ "\n")) .> wrapInParens
.> parseHsStrToQQExp str
.> return

removeLineComments = id
.> lines
Expand Down Expand Up @@ -90,15 +96,15 @@ joinAsColumns = sequenceA .> fmap (intercalate [qc|{nl} ++ "\t " ++ |])
wrapInParens :: HsExp String -> HsExp String
wrapInParens = fmap Utils.wrapInParens

parseHsStrToQQExp :: String -> HsExp String -> Exp
parseHsStrToQQExp :: String -> HsExp String -> Q Exp
parseHsStrToQQExp original = id
.> unHsExp
.> \s -> s $> id
.> parseExp
.> let e =
[qc|Debug.Dump: parseHsStrToQQExp:{indent 2 original}{indent 10 s})|] in id
.> let ef = (e ++) .> error in id
.> either ef id
.> let ef = (e ++) .> fail in id
.> either ef pure

nl = "\n"

Expand Down