From c620acddd34a07edd6f33baad0adfad6e8cf1bd5 Mon Sep 17 00:00:00 2001 From: Pearu Peterson Date: Wed, 4 Oct 2006 09:49:54 +0000 Subject: F2PY G3: exposed wrappers via f2py script. A working example: wrap F90 module containing derived type with scalar components. --- numpy/f2py/lib/parser/api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'numpy/f2py/lib/parser/api.py') 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 -- cgit v1.2.1