Parsing files -- pyparsing to the rescue?

rh0dium sklass at pointcircle.com
Mon Jan 16 16:01:36 EST 2006


Hi all,

I have a file which I need to parse and I need to be able to break it
down by sections.  I know it's possible but I can't seem to figure this
out.

    The sections are broken by <> with one or more keywords in the <>.
What I want to do is to be able to pars a particular section of the
file.  So for example I need to be able to look at the SYSLIB section.
Presumably the sections are


<SYSLIB>
Sys Data
Sys-Data
asdkData
Data
<LOGLVS>
Data
Data
Data
Data
<SOME SECTION>
Data
Data
Data
Data
<NETLIST>
Data
Data
Data
Data
<NET>

So if I wanted to break them down..

Sections are broken down by this..

secH=pyparsing.LineStart() + pyparsing.Suppress(
pyparsing.Literal("<")) +
pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums)) +
pyparsing.Suppress( pyparsing.Literal(">"))

But how do I say that <SECTIONn> stops at the start of the next
<SECTIONm>?




More information about the Python-list mailing list