Problem switching from PetitParser to PetitParser2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem switching from PetitParser to PetitParser2

Peter Kenny

Hello

 

I have been switching part of a package called TextLint so that it uses PetitParser2 as the parsing engine. For the most part it went fairly smoothly, but I have one problem which occurs in many places. The original parse rules had many conditional matching rules based on PPPredicateObjectParser. I have changed this to PP2PredicateObjectNode, using the same block as a predicate in each case. All of them fail when I test run them in a playground; in every case the error message is of the form: ‘Character does not understand [some condition testing method]’. The condition being tested is meaningless for a character – it applies to a token produced by some earlier parsing.

 

Looking at the code for PP2PredicateObjectNode>>#predicate:, I see that the predicate is always treated as a PP2CharSetPredicate, which is claimed to be a performance optimization. The error messages I have seen come from the initialization of this, setting up the 255 precomputed results, because they all relate to a character with asciiValue = 1.

 

All these rules worked in PetitParser, because the methods for PPPredicateObjectParser allow one to distinguish between a character set predicate and a general block; in fact, the class side contains a large variety of methods for generating conditions. As far as I can see, PP2PredicateObjectNode allows only one type of condition. Have I misunderstood – is there some way to specify the condition is not a character set?

 

Thanks for any help

 

Peter Kenny