Hi all,
I am trying to implement a small "island parser" in PetitParser, but I have a problem. The following is the most self contained example I can think of, it is able to extract the word 'island' from any context.
I have the class IslandSyntax, subclass of PPCompositeParser, with the following methods:
=== IslandSyntax>>start ^world end
IslandSytntax>>world world := PPUnresolvedParser new. world def: (island , world) / island / (water,world) / water. ^world.
IslandSyntax>>island ^'island' asParser
IslandSyntax>>water ^((island not), #any asParser) ==> #second ===
Then, I have IslandParser a subclass of IslandSyntax:
=== IslandParser>>island ^super island ==> [:result | result inspect] ===
If I open a workspace and do:
IslandParser new parse: 'blablablaislandblablabla'.
The inspect on island is called only once, while if I do:
IslandParser new parse: 'island'.
the inspector is called twice, probably because in the "world" production I first put (island , world) and then (island). Is there a way to avoid this double calling? Am I doing anything wrong here?
Thank you!
Alberto