pyparsing with nested table

Paul McGuire ptmcg at austin.rr.com
Thu Dec 8 04:57:14 EST 2005


astarocean wrote:
> using pyparsing to deal with nested tables , wanna keep table's
> structure and propertys .
> but program was chunked with the </td> tag of inner table.
>
> have any ideas?
>
> here's the program
>
>
> from pyparsing import *
   <... snip ...>
>
> tablePattern = Forward()
   <... snip ...>
> tablePattern = getMultiLevelPattern('table',trPattern)
> t = tablePattern
> for toks,strt,end in t.scanString(mytable):
>     print toks.asList()
>

Load Forward's with '<<' instead of '='.  Change:
  tablePattern = getMultiLevelPattern('table',trPattern)
to:
  tablePattern << getMultiLevelPattern('table',trPattern)

I think that is all you needed.

Awesome job!  (Also check out the pyparsing built-ins for making HTML
and XML tags.)

-- Paul




More information about the Python-list mailing list