summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/parsefortran.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/f2py/lib/parsefortran.py')
-rw-r--r--numpy/f2py/lib/parsefortran.py69
1 files changed, 59 insertions, 10 deletions
diff --git a/numpy/f2py/lib/parsefortran.py b/numpy/f2py/lib/parsefortran.py
index 89d793a52..380c10ffd 100644
--- a/numpy/f2py/lib/parsefortran.py
+++ b/numpy/f2py/lib/parsefortran.py
@@ -11,8 +11,9 @@ Created: May 2006
"""
import re
-
-from numpy.distutils.misc_util import yellow_text
+import sys
+import traceback
+from numpy.distutils.misc_util import yellow_text, red_text
from readfortran import FortranFileReader, FortranStringReader
from block import Block
@@ -25,7 +26,8 @@ class FortranParser:
def get_item(self):
try:
- return self.reader.next(ignore_comments = True)
+ item = self.reader.next(ignore_comments = True)
+ return item
except StopIteration:
pass
@@ -33,9 +35,20 @@ class FortranParser:
self.reader.fifo_item.insert(0, item)
def parse(self):
- main = Block(self)
- main.fill()
- return main
+ import init
+ try:
+ main = Block(self)
+ main.fill()
+ return main
+ except KeyboardInterrupt:
+ raise
+ except:
+ message = self.reader.format_message('FATAL ERROR',
+ 'while processing line',
+ self.reader.linecount, self.reader.linecount)
+ self.reader.show_message(message, sys.stdout)
+ traceback.print_exc(file=sys.stdout)
+ self.reader.show_message(red_text('STOPPED PARSING'), sys.stdout)
def test_pyf():
string = """
@@ -45,13 +58,36 @@ python module foo
real r
end subroutine bar
end interface
-end python module
+end python module foo
"""
reader = FortranStringReader(string, True, True)
parser = FortranParser(reader)
block = parser.parse()
print block
+def test_free90():
+ string = """
+module foo
+
+ subroutine bar
+ real r
+ if ( pc_get_lun() .ne. 6) &
+ write ( pc_get_lun(), '( &
+ & /, a, /, " p=", i4, " stopping c_flag=", a, &
+ & /, " print unit=", i8)') &
+ trim(title), pcpsx_i_pel(), trim(c_flag), pc_get_lun()
+ if (.true.) then
+ call smth
+ end if
+ end subroutine bar
+
+end module foo
+"""
+ reader = FortranStringReader(string, True, False)
+ parser = FortranParser(reader)
+ block = parser.parse()
+ print block
+
def test_f77():
string = """\
c program foo
@@ -68,13 +104,26 @@ c program foo
def simple_main():
import sys
for filename in sys.argv[1:]:
- print yellow_text('Processing '+filename)
reader = FortranFileReader(filename)
+ print yellow_text('Processing '+filename+' (mode=%r)' % (reader.mode))
+
parser = FortranParser(reader)
block = parser.parse()
- #print block
-
+ print block
+
+def profile_main():
+ import hotshot, hotshot.stats
+ prof = hotshot.Profile("_parsefortran.prof")
+ prof.runcall(simple_main)
+ prof.close()
+ stats = hotshot.stats.load("_parsefortran.prof")
+ stats.strip_dirs()
+ stats.sort_stats('time', 'calls')
+ stats.print_stats(30)
+
if __name__ == "__main__":
#test_f77()
+ #test_free90()
#test_pyf()
simple_main()
+ #profile_main()