diff options
author | Travis Oliphant <oliphant@enthought.com> | 2004-08-31 01:00:05 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2004-08-31 01:00:05 +0000 |
commit | 2f080bcf577a3d641cb1e7cd2069314547c22855 (patch) | |
tree | 34e6e87e0925f302c427fe4a9d93e94e4574a0f7 | |
parent | 965e6c6979cf1a73c5667a9595f0c19a28abbb9a (diff) | |
download | numpy-2f080bcf577a3d641cb1e7cd2069314547c22855.tar.gz |
Updated from_template to avoid recursion errors and fix bug.
-rwxr-xr-x | scipy_distutils/from_template.py | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/scipy_distutils/from_template.py b/scipy_distutils/from_template.py index dbf89aed3..b19262e06 100755 --- a/scipy_distutils/from_template.py +++ b/scipy_distutils/from_template.py @@ -36,23 +36,42 @@ else: False = 0 True = 1 -comment_block_exp = re.compile(r'/\*(?:\s|.)*?\*/') -subroutine_exp = re.compile(r'subroutine (?:\s|.)*?end subroutine.*') -function_exp = re.compile(r'function (?:\s|.)*?end function.*') +comment_block_exp = re.compile(r'/\*.*?\*/',re.DOTALL) +# These don't work with Python2.3 : maximum recursion limit exceeded. +#subroutine_exp = re.compile(r'subroutine (?:\s|.)*?end subroutine.*') +#function_exp = re.compile(r'function (?:\s|.)*?end function.*') reg = re.compile(r"\ssubroutine\s(.+)\(.*\)") def parse_structure(astr): spanlist = [] - for typ in [subroutine_exp, function_exp]: - ind = 0 - while 1: - a = typ.search(astr[ind:]) - if a is None: - break - tup = a.span() - tup = (ind+tup[0],ind+tup[1]) - spanlist.append(tup) - ind = tup[1] + # subroutines + ind = 0 + while 1: + start = astr.find("subroutine", ind) + if start == -1: + break + fini1 = astr.find("end subroutine",start) + fini2 = astr.find("\n",fini1) + spanlist.append((start, fini2)) + ind = fini2 + + # functions + ind = 0 + while 1: + start = astr.find("function", ind) + if start == -1: + break + pre = astr.rfind("\n", ind, start) + presave = start + # look for "$" in previous lines + while '$' in astr[pre:presave]: + presave = pre + pre = astr.rfind("\n", ind, pre-1) + + fini1 = astr.find("end function",start) + fini2 = astr.find("\n",fini1) + spanlist.append((pre+1, fini2)) + ind = fini2 spanlist.sort() return spanlist @@ -111,7 +130,7 @@ def expand_sub(substr,extra=''): numsubs = None for rep in reps: name = rep[0].strip().lower() - thelist,num = conv(rep[1]) + thelist = conv(rep[1]) _names[name] = thelist substr = named_re.sub(r"<\1>",substr) # get rid of definition templates |