[Pharo-project] petit parser help

Lukas Renggli renggli at gmail.com
Tue Apr 26 07:27:19 CEST 2011


> 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



More information about the Pharo-project mailing list