Type class describing parser monads that can trace during evaluation.
Methods
dbg :: Show a => String -> m a -> m adbg label pparser works exactly likep, but when it's evaluated it prints information useful for debugging. Thelabelis only used to refer to this parser in the debugging output. This combinator uses the trace function from Debug.Trace under the hood.Typical usage is to wrap every sub-parser in misbehaving parser with dbg assigning meaningful labels. Then give it a shot and go through the print-out. As of current version, this combinator prints all available information except for hints, which are probably only interesting to the maintainer of Megaparsec itself and may be quite verbose to output in general. Let me know if you would like to be able to see hints in the debugging output.
The output itself is pretty self-explanatory, although the following abbreviations should be clarified (they are derived from the low-level source code):
COK—“consumed OK”. The parser consumed input and succeeded.CERR—“consumed error”. The parser consumed input and failed.EOK—“empty OK”. The parser succeeded without consuming input.EERR—“empty error”. The parser failed without consuming input.
Note: up until the version 9.3.0 this was a non-polymorphic function that worked only in ParsecT. It was first introduced in the version 7.0.0.
Instances9MonadParsecDbg, …
MonadParsecDbg e s m => MonadParsecDbg e s (IdentityT m)Defined in megaparsec-9.7.0 · Text.Megaparsec.DebugMonadParsecDbg e s m => MonadParsecDbg e s (ReaderT r m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debug(Monoid w, Show w, MonadParsecDbg e s m) => MonadParsecDbg e s (WriterT w m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debugdbg (p :: WriterT st m)prints only log produced byp:Example2 expressions p = tell [0] >> dbg "a" (single 'a' >> tell [1])parseTest (runWriterT p) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (LOG: [1])((),[0,1])
(Monoid w, Show w, MonadParsecDbg e s m) => MonadParsecDbg e s (WriterT w m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debugdbg (p :: WriterT st m)prints only log produced byp:Example2 expressions p = tell [0] >> dbg "a" (single 'a' >> tell [1])parseTest (runWriterT p) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (LOG: [1])((),[0,1])
(Show st, MonadParsecDbg e s m) => MonadParsecDbg e s (StateT st m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debugdbg (p :: StateT st m)prints state after runningp:Example2 expressions p = modify succ >> dbg "a" (single 'a' >> modify succ)parseTest (runStateT p 0) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (STATE: 2)((),2)
(Show st, MonadParsecDbg e s m) => MonadParsecDbg e s (StateT st m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debugdbg (p :: StateT st m)prints state after runningp:Example2 expressions p = modify succ >> dbg "a" (single 'a' >> modify succ)parseTest (runStateT p 0) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (STATE: 2)((),2)
(VisualStream s, ShowErrorComponent e) => MonadParsecDbg e s (ParsecT e s m)Defined in megaparsec-9.7.0 · Text.Megaparsec.Debug(Monoid w, Show w, Show st, MonadParsecDbg e s m) => MonadParsecDbg e s (RWST r w st m)Defined in megaparsec-9.7.0 · Text.Megaparsec.DebugRWSTworks likeStateTinside aWriterT: subparser's log and its final state is printed:Example2 expressions p = tell [0] >> modify succ >> dbg "a" (single 'a' >> tell [1] >> modify succ)parseTest (runRWST p () 0) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (STATE: 2) (LOG: [1])((),2,[0,1])
(Monoid w, Show w, Show st, MonadParsecDbg e s m) => MonadParsecDbg e s (RWST r w st m)Defined in megaparsec-9.7.0 · Text.Megaparsec.DebugRWSTworks likeStateTinside aWriterT: subparser's log and its final state is printed:Example2 expressions p = tell [0] >> modify succ >> dbg "a" (single 'a' >> tell [1] >> modify succ)parseTest (runRWST p () 0) "a"a> IN: 'a'a> MATCH (COK): 'a'a> VALUE: () (STATE: 2) (LOG: [1])((),2,[0,1])