swift-parsing-dump #212
randomeizer
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I put together a little tool to help with debugging complex parsers called swift-parsing-dump.
Basically, it lets you do a customDump on the input and output of either
parse
orprint
calls.For example, you have an
Email
type and a parser for it:Unfortunately, this results in an error:
"But why?" you ask. There is an "@" right there! Let's do some dumping:
Now, when I run it (in DEBUG), I get this in the console:
Oh, right,
PrefixThrough
consumes the delimiter character. I just need to switch toPrefixUpTo("@")
instead:Now I run it, no errors, and I get this in the console:
Sweet.
Obviously a simple example, but parsers can get quite nested, and busting out specific-case unit tests can take time. It's also limited when working with more complex parsers like
OneOf
orMany
, since it's running multiple parsers under the hood.Anyway, hopefully that's useful to someone else out there!
Beta Was this translation helpful? Give feedback.
All reactions