Printing Not and Peek #144
randomeizer
started this conversation in
Ideas
Replies: 3 comments
-
I've posted a PR in #145 as an implementation of this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Moved comment to PR #145 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm going to delete and repost my comment in the PR and we can continue any discussion over there. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @stephencelis, continuing the discussion from PR #97, which is now closed. For context, we were discussing that
Not
andPeek
are 'unprintable'.Having had a chance to look at the
printer-throws-2
branch, and I see what you mean with regards to it allowing "invalid" prints with code like this:I think the only solution would be to have
Parse
actually print to theinput
in reverse order. Not onlyParse
, but everything. Everything gets printed depth-first.In that case,
Not
would attempt toparse
the current printed value to check if it was valid against its internalupstream
parser. If it parses successfully, it throws an error.Printing backwards seems illogical, but if you think about it, we parse from outer to inner, so printing from inner to outer makes sense.
Example implementation of
Not.print(...)
, if printing in reverse:This obviously won't work for
uncommentedLine
unless thePrefix
parser has already printed. However, it would also letPrefix
check that it is outputting correctly first. It'sprint
could look like this:Each of the
ZipX
parsers would then become something like:Kind of unintuitive, but I think it would actually be more correct.
Beta Was this translation helpful? Give feedback.
All reactions