Re: [Pyparsing] Debugging Pyparsing
Brought to you by:
ptmcg
From: <pt...@au...> - 2009-10-30 02:18:11
|
---- Daniel Erenrich <ere...@ca...> wrote: > When debugging pyparsing I love to use the setDebug function. Sometimes > though this becomes tedious since I do not really know what path the > parser took before blowing up. Is there any easy way to setDebug() on > all parsing elements that I defined? Or just all named parsing elements? > Here's a short cut I use some times. Say I have a parser with expressions in it that I want to name and set debug on, and the expressions are in variables ident, integer, float_, and phonenum: for ename in "ident integer float_ phonenum".split(): expr = locals()[ename] expr.setName(ename) expr.setDebug() I first got this idea from Seo Sanghyeon, who used something like this in the ebnf.py EBNF parser, which you can find on the pyparsing wiki's Examples page. > On an unrelated note, why are there no built-ins for matching > integers/floats. This seems like a very common task that I keep reinventing. > Hmm, no special reason. I think I have some already in the Helpful Expressions page of the wiki. Integer form is pretty clear cut, could be added without much pain. But should the floats include scientific notation too? Leading zero required for floats < 1? At least one zero required after the '.'? If these are for your own personal consumption only, you might just drop them into a pyparsing_snippets.py module in your own site-packages directory. But if there is more feedback on the list asking for these, I don't mind adding them. -- Paul |