Hi Frank,
I forward this to the Moose list (most PP action is going on there),
because other people might be interested as well.
On Wednesday, 20 July 2011, Frank Shearar <frank.shearar(a)gmail.com> wrote:
Hi Lukas,
I've been playing around with PetitParser lately
(
http://www.lshift.net/blog/2011/07/19/un-petit-haskell), and I
thought (a) I'd tell you about another happy user and (b) share a
trick, which you may already know. A println analogue for debugging
one's productions, occasionally useful when one runs too far ahead of
one's tests:
PPParser>>debug: aString
^ self ==> [:x | Transcript showln: ('{1} ({2})' format: {aString.
x.}). x].
You might be also be interested in #>=> that passes you a continuation
into the block, so it allows you to "debug" before and after the
parse. I used it to write the Glamour-based debugger. Look at the
tests for more details.
One problem I have found is that PetitStream
doesn't work well
wrapping a (Squeak) FileStream. I had expected the following to just
work:
FileStream
fileNamed: 'myFile'
do: [:f | HaskellParser new parse: f]
but I currently have to read the entire file into a String and parse
that. I'm don't know if that's because of a difference between
Squeak's and Pharo's FileStream implementation or a problem in
PetitParer?
It should work, but convert the stream to a PPStram using
#asPetitStream. I cannot verify right now, because I don't have a
computer accessible. Parsing directly on a filestream could
potentially work (you might need to implement #uncheckedPeek) but will
be dead slow (PP extensively uses #position: and #next to randomly
acces the stream, as you can see on Figure 2 in
http://scg.unibe.ch/archive/papers/Reng10cDynamicGrammars.pdf).
Thanks for sharing your blog post and experience!
Lukas
--
Lukas Renggli
www.lukas-renggli.ch