New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pTrace function #63

Closed
gbaz opened this Issue Nov 21, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@gbaz
Contributor

gbaz commented Nov 21, 2016

Here's a basic tool I hacked up back in the day to help in debugging parsers, and I've found it indispensable.

@pchiusano added a wrapper to show backtracking too.

I don't have a strong opinion on where it lands in the parsec package, but it seems that a few people have now found it useful and it only really exists as folklore. It would be nice to add it to the parsec package proper in an appropriate location:

pTrace s = pt <|> return ()
    where pt = try $
               do
                 x <- try $ many1 anyChar
                 trace (s++": " ++x) $ try $ char 'z'
                 fail x

pTraced s p = do
  pTrace s
  p <|> trace (s ++ " backtracked") (fail s)
@jwiegley

This comment has been minimized.

jwiegley commented Nov 29, 2016

Note that my parsec-free module on Hackage will now give you complete tracing of any Parsec parser, without modification (you simply call parseTestLog instead of parseTest, after changing your Cabal dependencies to refer to parsec-free). An example of the output is given here.

@hvr hvr added this to the 3.1.12 (API addition) milestone Jun 22, 2017

@hvr hvr added the pvp:minor label Jun 22, 2017

@hvr hvr closed this in #85 Dec 31, 2017

hvr added a commit that referenced this issue Dec 31, 2017

Add parserTrace and parserTraced functions (#85)
`parserTrace label` is an impure function, implemented with "Debug.Trace" that
prints to the console the remaining parser state at the time it is invoked.
It is intended to be used for debugging parsers by inspecting their intermediate states.

These are simple yet helpful helpers for debugging Parsec parsers.

Closes #63

hvr added a commit that referenced this issue Dec 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment