|
1 | 1 | import re |
2 | | -from functools import reduce |
3 | | -from typing import List, Optional, Tuple |
| 2 | +from typing import List, Optional, Tuple, cast |
4 | 3 |
|
5 | 4 | from .ast import Location |
6 | 5 | from .location import SourceLocation, get_location |
@@ -40,20 +39,20 @@ def get_line(index: int) -> Optional[str]: |
40 | 39 |
|
41 | 40 | return f"{source.name}:{line_num}:{column_num}\n" + print_prefixed_lines( |
42 | 41 | [ |
43 | | - (f"{line_num - 1}: ", get_line(line_index - 1)), |
44 | | - (f"{line_num}: ", get_line(line_index)), |
| 42 | + (f"{line_num - 1}", get_line(line_index - 1)), |
| 43 | + (f"{line_num}", get_line(line_index)), |
45 | 44 | ("", " " * (column_num - 1) + "^"), |
46 | | - (f"{line_num + 1}: ", get_line(line_index + 1)), |
| 45 | + (f"{line_num + 1}", get_line(line_index + 1)), |
47 | 46 | ] |
48 | 47 | ) |
49 | 48 |
|
50 | 49 |
|
51 | 50 | def print_prefixed_lines(lines: List[Tuple[str, Optional[str]]]) -> str: |
52 | | - """Print lines specified like this: ["prefix", "string"]""" |
53 | | - existing_lines = [line for line in lines if line[1] is not None] |
54 | | - pad_len = reduce(lambda pad, line: max(pad, len(line[0])), existing_lines, 0) |
| 51 | + """Print lines specified like this: ("prefix", "string")""" |
| 52 | + existing_lines = [ |
| 53 | + cast(Tuple[str, str], line) for line in lines if line[1] is not None |
| 54 | + ] |
| 55 | + pad_len = max(len(line[0]) for line in existing_lines) |
55 | 56 | return "\n".join( |
56 | | - map( |
57 | | - lambda line: line[0].rjust(pad_len) + line[1], existing_lines # type:ignore |
58 | | - ) |
| 57 | + map(lambda line: line[0].rjust(pad_len) + " | " + line[1], existing_lines) |
59 | 58 | ) |
0 commit comments