Transform a help command found by the ``find()`` classmethod.
(self, lines)
| 440 | return cls(line[ix].start, line[-2].start) |
| 441 | |
| 442 | def transform(self, lines): |
| 443 | """Transform a help command found by the ``find()`` classmethod. |
| 444 | """ |
| 445 | piece = ''.join(lines[self.start_line:self.q_line+1]) |
| 446 | indent, content = piece[:self.start_col], piece[self.start_col:] |
| 447 | lines_before = lines[:self.start_line] |
| 448 | lines_after = lines[self.q_line + 1:] |
| 449 | |
| 450 | m = _help_end_re.search(content) |
| 451 | if not m: |
| 452 | raise SyntaxError(content) |
| 453 | assert m is not None, content |
| 454 | target = m.group(1) |
| 455 | esc = m.group(3) |
| 456 | |
| 457 | # If we're mid-command, put it back on the next prompt for the user. |
| 458 | next_input = None |
| 459 | if (not lines_before) and (not lines_after) \ |
| 460 | and content.strip() != m.group(0): |
| 461 | next_input = content.rstrip('?\n') |
| 462 | |
| 463 | call = _make_help_call(target, esc, next_input=next_input) |
| 464 | new_line = indent + call + '\n' |
| 465 | |
| 466 | return lines_before + [new_line] + lines_after |
| 467 | |
| 468 | def make_tokens_by_line(lines:List[str]): |
| 469 | """Tokenize a series of lines and group tokens by line. |