re question
Daniel Schüle
uval at rz.uni-karlsruhe.de
Fri Jun 23 11:21:54 EDT 2006
Hi
[...]
hm, that's wired
I just tried it in python shell and it works but same code as script file
fails
for anyone who want to see for himself
# package.vhd file
bash % cat package.vhd
library ieee;
use ieee.std_logic_1164.all;
package TEST123 is
constant BASE
End Package Test;
# parser.py
bash % cat parser.py
#!/usr/bin/env python
import sys, re
reflags = re.DOTALL | re.MULTILINE | re.IGNORECASE
pattern =
re.compile(r'^\s*package\s+(?P<name>\w+)\s+is\s+(?P<content>.*?)\s+end(\s+package)?(\s+(?P=name))?\s*;',
reflags)
class PackageParser(object):
def __init__(self, filename):
self.package = file(filename).read()
def parse(self):
return pattern.search(self.package)
if __name__ == "__main__":
p = PackageParser("package.vhd")
m = p.parse()
if m is None:
print "nothing"
sys.exit(1)
print m.group("content")
print m.group("name")
# testing
bash % ./parser.py
nothing
ps:
>>> sys.version
'2.4.2 (#2, Mar 3 2006, 13:32:59) \n[GCC 3.2.2 20030222 (Red Hat Linux
3.2.2-5)]'
Regards, Daniel
More information about the Python-list
mailing list