Return a list of tuples for each function or subroutine each tuple is the start and end of a subroutine or function to be expanded.
(astr)
| 52 | function_start_re = re.compile(r'\n (\$|\*)\s*function\b', re.I) |
| 53 | |
| 54 | def parse_structure(astr): |
| 55 | """ Return a list of tuples for each function or subroutine each |
| 56 | tuple is the start and end of a subroutine or function to be |
| 57 | expanded. |
| 58 | """ |
| 59 | |
| 60 | spanlist = [] |
| 61 | ind = 0 |
| 62 | while True: |
| 63 | m = routine_start_re.search(astr, ind) |
| 64 | if m is None: |
| 65 | break |
| 66 | start = m.start() |
| 67 | if function_start_re.match(astr, start, m.end()): |
| 68 | while True: |
| 69 | i = astr.rfind('\n', ind, start) |
| 70 | if i==-1: |
| 71 | break |
| 72 | start = i |
| 73 | if astr[i:i+7]!='\n $': |
| 74 | break |
| 75 | start += 1 |
| 76 | m = routine_end_re.search(astr, m.end()) |
| 77 | ind = end = m and m.end()-1 or len(astr) |
| 78 | spanlist.append((start, end)) |
| 79 | return spanlist |
| 80 | |
| 81 | template_re = re.compile(r"<\s*(\w[\w\d]*)\s*>") |
| 82 | named_re = re.compile(r"<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>") |