You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some parser combinators which perform tests (look-aheads and stuff). The way I went about and implemented their printer counterpart is that the printer simply ignores the test.
The current guilty parties are
eof: the printer is a no-op.
Is it fine? or should it somehow make sure that nothing is printed after? (so that, say eof *> string "foo" wouldn't print an unparsable result (namely foo))
lookAhead: in parsers, lookAhead prse check that the parser prse can consume a prefix of the input (but doesn't consume input). In printers, it simply a no-op.
In particular we can't verify that prse will indeed be able to parse whatever is coming next. But it's a little trickier than the case of eof. Inded, the printer side is defined as lookAhead prnt, taking an inner printer instead of parser, and really, the only sensible thing to do is to ignore this printer. Validating that the output can be parsed back would require a much deeper integration of parsers and printers. I'm not sure how we could do that not too obnoxiously.
Anyway, this discussion is open to be able to gather feedback on whether these simple printers are ok in practice, or if they are unreasonable foot-guns. And discuss ideas of how improved versions can be implemented.
Note that printers in this setting are (necessarily) partial, so we have the means and reason to reject wrong outputs. Arguably a worse outcome than printing something unparsable is taking the wrong branch of an alternative and printing something which is parsable but parsed into something else entirely.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
There are some parser combinators which perform tests (look-aheads and stuff). The way I went about and implemented their printer counterpart is that the printer simply ignores the test.
The current guilty parties are
eof
: the printer is a no-op.eof *> string "foo"
wouldn't print an unparsable result (namelyfoo
))lookAhead
: in parsers,lookAhead prse
check that the parserprse
can consume a prefix of the input (but doesn't consume input). In printers, it simply a no-op.prse
will indeed be able to parse whatever is coming next. But it's a little trickier than the case ofeof
. Inded, the printer side is defined aslookAhead prnt
, taking an inner printer instead of parser, and really, the only sensible thing to do is to ignore this printer. Validating that the output can be parsed back would require a much deeper integration of parsers and printers. I'm not sure how we could do that not too obnoxiously.Anyway, this discussion is open to be able to gather feedback on whether these simple printers are ok in practice, or if they are unreasonable foot-guns. And discuss ideas of how improved versions can be implemented.
Note that printers in this setting are (necessarily) partial, so we have the means and reason to reject wrong outputs. Arguably a worse outcome than printing something unparsable is taking the wrong branch of an alternative and printing something which is parsable but parsed into something else entirely.
Beta Was this translation helpful? Give feedback.
All reactions