(text)
| 56 | return None |
| 57 | |
| 58 | def build_index(text): |
| 59 | |
| 60 | index = {} |
| 61 | pattern_re = re.compile( |
| 62 | r'(?P<topic>\D.+?) (?:see (?P<see_ref>.*)|(?P<pages>[0-9,\-n]+(?!\.)) ?(?P<subtopic>.*))') |
| 63 | |
| 64 | for line in text: |
| 65 | if line == '': |
| 66 | continue |
| 67 | if opts.debug: |
| 68 | print 'line =', line |
| 69 | topic, see_ref, pages, subtopic = pattern_re.match(line).groupdict().values() |
| 70 | topic, see_ref, pages, subtopic = map(strip_var, (topic, see_ref, pages, subtopic)) |
| 71 | chunks = topic.split(' ') |
| 72 | if len(chunks) > 1: |
| 73 | if a_name(chunks[0]): |
| 74 | pre, last = topic.split(' ', 1) |
| 75 | topic = chunks[-1] + ', ' + ' '.join(chunks[0:-1]) |
| 76 | if topic not in index: |
| 77 | index[topic] = {} |
| 78 | if see_ref: |
| 79 | if see_ref.startswith('also '): |
| 80 | index[topic].setdefault('also', []).append(see_ref[5:]) |
| 81 | else: |
| 82 | index[topic].setdefault('see', []).append(see_ref) |
| 83 | elif subtopic: |
| 84 | index[topic].setdefault('subtopics', {}).setdefault(subtopic, []).append(pages) |
| 85 | else: |
| 86 | index[topic].setdefault('pages', []).append(pages) |
| 87 | return index |
| 88 | |
| 89 | def entitle(s): |
| 90 | '''title case first word of refs |
no test coverage detected