summaryrefslogtreecommitdiff
path: root/numpy/f2py/lib/parser/api.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-10-04 09:49:54 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-10-04 09:49:54 +0000
commitc620acddd34a07edd6f33baad0adfad6e8cf1bd5 (patch)
tree3413710782a3f16711c4935cde86fbb5e69c35dd /numpy/f2py/lib/parser/api.py
parentac93e95702a9047b774b4cdd1838c9e1b1f70739 (diff)
downloadnumpy-c620acddd34a07edd6f33baad0adfad6e8cf1bd5.tar.gz
F2PY G3: exposed wrappers via f2py script. A working example: wrap F90 module containing derived type with scalar components.
Diffstat (limited to 'numpy/f2py/lib/parser/api.py')
-rw-r--r--numpy/f2py/lib/parser/api.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/f2py/lib/parser/api.py b/numpy/f2py/lib/parser/api.py
index 0a7346095..4b3ea88fa 100644
--- a/numpy/f2py/lib/parser/api.py
+++ b/numpy/f2py/lib/parser/api.py
@@ -30,9 +30,24 @@ def parse(input, isfree=None, isstrict=None, include_dirs = None):
and the directory of file name.
"""
import os
+ import re
from readfortran import FortranFileReader, FortranStringReader
from parsefortran import FortranParser
if os.path.isfile(input):
+ name,ext = os.path.splitext(input)
+ if ext.lower() in ['.c']:
+ # get signatures from C file comments starting with `/*f2py` and ending with `*/`.
+ # TODO: improve parser to take line number offset making line numbers in
+ # parser messages correct.
+ f2py_c_comments = re.compile('/[*]\s*f2py\s.*[*]/',re.I | re.M)
+ f = open(filename,'r')
+ c_input = ''
+ for s1 in f2py_c_comments.findall(f.read()):
+ c_input += s1[2:-2].lstrip()[4:] + '\n'
+ f.close()
+ if isfree is None: isfree = True
+ if isstrict is None: isstrict = True
+ return parse(c_input, isfree, isstrict, include_dirs)
reader = FortranFileReader(input,
include_dirs = include_dirs)
if isfree is None: isfree = reader.isfree