Re: [Pyparsing] Order problem in binary operation withoperationPrecedence()
Brought to you by:
ptmcg
From: Ralph C. <ra...@in...> - 2009-07-11 12:43:46
|
hi Gustavo, > > 2. > > relationals = eq ^ ne ^ lt ^ gt ^ le ^ ge > > > > '^' can be relatively expensive for pyparsing if there are many > > alternatives, since all alternatives will be checked. This version > > is equivalent: > > > > relationals = eq | ne | le | ge | lt | gt > > Thanks for the hint. I used pipes initially but for some reason some > tests didn't pass... I've just restored the pipes and the all the > tests pass now, though :-S > > > (I *did* have to be careful about the order, having to check for > > "<=" before "<", and ">=" before ">".) > > Could you please elaborate on that? Is it for performance reasons? `^' causes all alternatives to be tested, `|' stops at the first one that succeeds. If using `|', unless you test for `<=' before `<' then `<=' would never be seen because it would always look like a `<'. With `^', I assume the longest one that succeeds is used so both `<' and `<=' match but the latter is used. Cheers, Ralph. |