summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/parser/api.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-10-01 11:49:23 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-10-01 11:49:23 +0000
commitc3c53e6805beb164581f041a69c9f51c2740d344 (patch)
tree70d942460a7624996b6a7ee0dd5e25c014b9772f /numpy/f2py/lib/parser/api.py
parent6c52e6fc05f89f13871b79074ea8891c11092d35 (diff)
downloadnumpy-c3c53e6805beb164581f041a69c9f51c2740d344.tar.gz
F2PY G3: Moved Fortran parser related code to subpackage parser.
Diffstat (limited to 'numpy/f2py/lib/parser/api.py')
-rw-r--r--numpy/f2py/lib/parser/api.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/numpy/f2py/lib/parser/api.py b/numpy/f2py/lib/parser/api.py
new file mode 100644
index 000000000..efcfcbf28
--- /dev/null
+++ b/numpy/f2py/lib/parser/api.py
@@ -0,0 +1,53 @@
+"""
+Public API for Fortran parser.
+
+-----
+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: Oct 2006
+-----
+"""
+
+# import all Statement classes:
+from block_statements import *
+
+# CHAR_BIT is used to convert object bit sizes to byte sizes
+from utils import CHAR_BIT
+
+def parse(input, isfree=None, isstrict=None, include_dirs = None):
+ """ Parse input and return Statement tree.
+
+ input --- string or filename.
+ isfree, isstrict --- specify input Fortran format.
+ Defaults are True, False, respectively, or
+ determined from input.
+ include_dirs --- list of include directories.
+ Default contains current working directory
+ and the directory of file name.
+ """
+ import os
+ from readfortran import FortranFileReader, FortranStringReader
+ from parsefortran import FortranParser
+ if os.path.isfile(input):
+ reader = FortranFileReader(input,
+ include_dirs = include_dirs)
+ if isfree is None: reader.isfree
+ if isstrict is None: reader.isstrict
+ reader.set_mode(isfree, isstrict)
+ elif isinstance(input, str):
+ if isfree is None: isfree = True
+ if isstrict is None: isstrict = False
+ reader = FortranStringReader(input,
+ isfree, isstrict,
+ include_dirs = include_dirs)
+ else:
+ raise TypeError,'Expected string or filename input but got %s' % (type(input))
+ parser = FortranParser(reader)
+ parser.parse()
+ parser.analyze()
+ return parser.block
+
+