[Pyparsing] packrat bug + various
Brought to you by:
ptmcg
From: Paolo L. <p....@hy...> - 2006-08-22 23:09:55
|
Hello Paul and everyone, I'm trying to upgrade my application from 1.3.3 to 1.4.3, mainly for the PackRat feature since I expect huge performance gain from it in my app. I'm finding some problems/bugs though... ### PackRat bug reuse of ParseResults strategy conflicts with PackRat ParseResult caching. For an example: ----------------------- from pyparsing import * A = Literal('A') B = Literal('B') C = Literal('C') e = A ^ ( A + B + C ) print e.parseString("AB") ParserElement.enablePackrat() print e.parseString("AB") ------------------------- The solution could be dropping the reuse strategy (drop __iadd__ and __new__ from ParseResults). I think that this not only would solve the bug but would also make the code easier to understand/maintain with a little sacrifice in performance (has the performance advantage ever been measured?). I know this is a drastic solution and I want to hear from you Paul since I'd like to keep in synch with your official releases... ### skipWhitespace bug I attach a small patch related to whitespaces skipping... ### PackRat threading enhancement Current packrat implementation seems to be thread safe but not thread friendly: a new thread, via resetCache(), forces a global cache flush also when other threads are running... I suggest making resetCache invocation explicit or make specific per thread cache... what do you think? ### Performance and simple code I see that in some points of the code (i.e. ParserElement._parse) some performance optimization is achieved by making the code a little bit more complex... IMVHO performance optimization should be obtained implementing the critical code in C (many other python projects follow the same rule: in python reference clean code implementation, in C functionally equivalent fast code. I volunteer for C implementation if we agree on the approach... main targets could be ParseResults and ParserElement._parse... Thank you very much for the fantastic work Ciao Paolo |