Re: [Pyparsing] Is it possible to optimize this grammar?
Brought to you by:
ptmcg
From: Gustavo N. <me...@gu...> - 2009-07-09 20:38:04
|
What!? I'd call this "Mega Turbo Button", not just packrat. ;-) "W == 0 | (X != 1 ^ (Y > 2 & Z < 3))" is parsed without packrat in 676.20 seconds. With packrat, it's parsed in 0.02 seconds! 33810x faster! And the best of all is that all my 500+ tests still pass. Now the test suite is run in just 1.53 seconds! This is just awesome. Thank you very much, Paul! - Gustavo. Paul said: > Parsers that have deep operatorPrecedence definitions often benefit from > using packrat parsing. Please insert this at the top of your module, right > after the import statement (you'll also have to add ParserElement to the > list of names imported from the pyparsing module): > > ParserElement.enablePackrat() > > > Packrat parsing is a kind of parse-time memoization. There is more info on > the FAQs page of the wiki. -- Gustavo Narea <xri://=Gustavo>. | Tech blog: =Gustavo/(+blog)/tech ~ About me: =Gustavo/about | |