mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-11-23 01:58:49 +03:00
Add a debugging helper that doesn't require a Show
instance
This commit is contained in:
parent
e6fbc3d822
commit
5d4e3e7cfd
@ -1,5 +1,8 @@
|
||||
## Megaparsec 9.1.0
|
||||
|
||||
* Added `dbg'` in `Text.Megaparsec.Debug` for debugging parsers that have
|
||||
unshowable return values.
|
||||
|
||||
* Documentation improvements.
|
||||
|
||||
## Megaparsec 9.0.1
|
||||
|
@ -16,6 +16,7 @@
|
||||
-- @since 7.0.0
|
||||
module Text.Megaparsec.Debug
|
||||
( dbg,
|
||||
dbg',
|
||||
)
|
||||
where
|
||||
|
||||
@ -88,6 +89,29 @@ dbg lbl p = ParsecT $ \s cok cerr eok eerr ->
|
||||
++ l (DbgEERR (streamTake (streamDelta s s') (stateInput s)) err)
|
||||
in unParser p s cok' cerr' eok' eerr'
|
||||
|
||||
-- | Just like 'dbg', but doesn't require the return value of the parser to
|
||||
-- be 'Show'-able.
|
||||
--
|
||||
-- @since 9.1.0
|
||||
dbg' ::
|
||||
forall e s m a.
|
||||
( VisualStream s,
|
||||
ShowErrorComponent e
|
||||
) =>
|
||||
-- | Debugging label
|
||||
String ->
|
||||
-- | Parser to debug
|
||||
ParsecT e s m a ->
|
||||
-- | Parser that prints debugging messages
|
||||
ParsecT e s m a
|
||||
dbg' lbl p = unBlind <$> dbg lbl (Blind <$> p)
|
||||
|
||||
-- | A wrapper type with a dummy 'Show' instance.
|
||||
newtype Blind x = Blind {unBlind :: x}
|
||||
|
||||
instance Show (Blind x) where
|
||||
show _ = "NOT SHOWN"
|
||||
|
||||
-- | A single piece of info to be rendered with 'dbgLog'.
|
||||
data DbgItem s e a
|
||||
= DbgIn [Token s]
|
||||
|
Loading…
Reference in New Issue
Block a user