[Pharo-project] petit parser help

Ricardo Moran richi.moran at gmail.com
Tue Apr 26 14:46:37 CEST 2011


Hi Lukas, thanks for answering!
Since all this stuff is pretty new to me sometimes is hard to see when
something is an optimization or the right way to do it :)

Cheers,
Richo

On Tue, Apr 26, 2011 at 2:27 AM, Lukas Renggli <renggli at gmail.com> wrote:

> > I only played a little with PetitParser but I think the answer is in
> > PetitXml>>#element. You see in the action block that it compares the
> > "qualified" of the open and close tags and if they're different it
> returns a
> > PPFailure. It also takes care of the inlineTag in the same block by
> asking
> > if the fifth node is '/>'.
>
> This "taking care of the inlineTag" is just an ugly optimization, but
> it makes the parser extremely fast :-)
>
> Ideally you start with a grammar as you propose and add then check if
> open and close tag are the same in the callback, as in the example
> above.
>
> Another subtlety that you see in the above example that is the parser:
>
>    [ :stream | stream position ] asParser
>
> This object returns the position in the stream and makes it possible
> to create the failure at the beginning of the close tag. Again, this
> is not required to start with. You can create the failure object like
> below, it just will not point you to the right place in the input
> then:
>
>    PPFailure message: 'tags not matching' at: 0
>
> Lukas
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20110426/49fef65a/attachment.htm>


More information about the Pharo-project mailing list