diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-05-24 13:44:36 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-05-24 13:44:36 +0000 |
commit | fff3c3f3b186d5a7cbbd3f4440b8f99f2035e733 (patch) | |
tree | 0704f51f408b86ac190aa07501f875858c792423 /numpy/f2py/lib/parsefortran.py | |
parent | f3d3c4bc5b59da6dc9cd0343aeaf523a71521408 (diff) | |
download | numpy-fff3c3f3b186d5a7cbbd3f4440b8f99f2035e733.tar.gz |
Impl. simple fortran parser.
Diffstat (limited to 'numpy/f2py/lib/parsefortran.py')
-rw-r--r-- | numpy/f2py/lib/parsefortran.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/numpy/f2py/lib/parsefortran.py b/numpy/f2py/lib/parsefortran.py new file mode 100644 index 000000000..d4dc3d594 --- /dev/null +++ b/numpy/f2py/lib/parsefortran.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +""" +Defines FortranParser. + +Permission to use, modify, and distribute this software is given under the +terms of the NumPy License. See http://scipy.org. +NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + +Author: Pearu Peterson <pearu@cens.ioc.ee> +Created: May 2006 +""" + +import re + +from readfortran import FortranFileReader, FortranStringReader +from block import Block + +class FortranParser: + + def __init__(self, reader): + self.reader = reader + + def get_item(self): + try: + return self.reader.next(ignore_comments = True) + except StopIteration: + pass + + def put_item(self, item): + self.reader.fifo_item.insert(0, item) + + def parse(self): + main = Block(self) + main.fill() + return main + +def test_pyf(): + string = """ +python module foo + interface + subroutine bar + real r + end subroutine bar + end interface +end python module +""" + reader = FortranStringReader(string, True, True) + reader = FortranFileReader(filename) + parser = FortranParser(reader) + block = parser.parse() + print block + +def simple_main(): + import sys + for filename in sys.argv[1:]: + print 'Processing',filename + reader = FortranFileReader(filename) + parser = FortranParser(reader) + block = parser.parse() + print block + +if __name__ == "__main__": + #test_pyf() + simple_main() |