help with pyparsing

Prabhu Gurumurthy pgurumur at gmail.com
Mon Dec 10 00:01:57 EST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

I have the following lines that I would like to parse in python using
pyparsing, but have some problems forming the grammar.

Line in file:
table <ALINK> const { 207.135.103.128/26, 207.135.112.64/29 }
table <INTRANET> persist { ! 10.200.2/24, 10.200/22 }
table <RFC_1918> const { 192.168/16, ! 172.24.1/29, 172.16/12, 169.254/16 }
table <DIALER> persist { 10.202/22 }
table <RAVPN> const { 10.206/22 }
table <KS> const {   \
   10.205.1/24,      \
   169.136.241.68,   \
   169.136.241.70,   \
   169.136.241.71,   \
   169.136.241.72,   \
   169.136.241.75,   \
   169.136.241.76,   \
   169.136.241.77,   \
   169.136.241.78,   \
   169.136.241.79,   \
   169.136.241.81,   \
   169.136.241.82,   \
   169.136.241.85 }

I have the following grammar defn.

tableName = Word(alphanums + "-" + "_")
leftClose = Suppress("<")
rightClose = Suppress(">")
key = Suppress("table")
tableType = Regex("persist|const")
ip4Address = OneOrMore(Word(nums + "."))
ip4Network = Group(ip4Address + Optional(Word("/") +
OneOrMore(Word(nums))))
temp = ZeroOrMore("\\" + "\n")
tableList = OneOrMore(Optional("\\") |
               ip4Network | ip4Address | Suppress(",") | Literal("!"))
leftParen = Suppress("{")
rightParen = Suppress("}")

table = key + leftClose + tableName + rightClose + tableType + \
                  leftParen + tableList + rightParen

I cannot seem to match sixth line in the file above, i.e table name with
KS, how do I form the grammar for it, BTW, I still cannot seem to ignore
comments using table.ignore(Literal("#") + restOfLine), I get a parse error.

Any help appreciated.
Thanks
Prabhu
- -
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFHXMhFTkjpaeKzB9YRAmZYAJ9Lyys6+xCrGEsyy33AoRWVdUOXQwCfTG9Q
/f7JZ2pAW6WDSzs79jbDFQE=
=CGb0
-----END PGP SIGNATURE-----



More information about the Python-list mailing list