-
Notifications
You must be signed in to change notification settings - Fork 38
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
Improve debugging: peek show next data in errors #46
Comments
I don't know if I'm missing something but I've been messing with parsy for a couple days and it's really hard to debug? |
I'm a bit hesitant to change the behaviour regarding error messages here, because it could affect so many users, and I don't know how to do it in a way that is generically useful. Do you have any ideas @jneen ? Parsy certainly doesn't have advanced features for syntax error reporting. If you are needing to pass on detailed parsing error message to end users (e.g. for a programming language), then it probably requires you to build this yourself, or use a different more heavyweight tool (e.g. lark perhaps?) For building parsers for small "languages", I've found it usually pretty easy to debug my code, by ensuring that I'm building up progressively larger parsers from smaller ones and testing piece by piece. I'm not sure what your use case is. |
I don't use combinators myself these days, for the exact reason that other approaches (for me, skeleton trees) result in better error messages. @deliciouslytyped do you mean debugging your parser or providing debugging information for your user? If it's the latter, I'd point you to the |
For debugging your own parsers, it may also be useful to add something like: class Debug(namedtuple('Debug', 'stream index')):
pass
debug = Parser(lambda stream, index: Result.success(index, Debug(stream, index))) or def debug_log(p, *args):
@Parser
def debug_parser(stream, index):
result = p(stream, index)
print(f"debug@{index}: '{stream[index:index+10]}' = {result}")
return debug_parser |
I'm talking about debugging my own parsers. Maybe it's just lot's of PEBCAK. Edit: rest of post moved to #48. Progressively building up parsers in small steps certainly does help. |
It would probably help a lot if error messages showed some of the upcoming data in parse errors with streams where this is possible (I don't know if parsy supports iterators).
The text was updated successfully, but these errors were encountered: