(
exc: tokenize.TokenError,
line_lengths: list[int],
last_emitted: ColorSpan | None,
buffer: str,
)
| 124 | |
| 125 | |
| 126 | def recover_unterminated_string( |
| 127 | exc: tokenize.TokenError, |
| 128 | line_lengths: list[int], |
| 129 | last_emitted: ColorSpan | None, |
| 130 | buffer: str, |
| 131 | ) -> Iterator[ColorSpan]: |
| 132 | msg, loc = exc.args |
| 133 | if loc is None: |
| 134 | return |
| 135 | |
| 136 | line_no, column = loc |
| 137 | |
| 138 | if msg.startswith( |
| 139 | ( |
| 140 | "unterminated string literal", |
| 141 | "unterminated f-string literal", |
| 142 | "unterminated t-string literal", |
| 143 | "EOF in multi-line string", |
| 144 | "unterminated triple-quoted f-string literal", |
| 145 | "unterminated triple-quoted t-string literal", |
| 146 | ) |
| 147 | ): |
| 148 | start = line_lengths[line_no - 1] + column - 1 |
| 149 | end = line_lengths[-1] - 1 |
| 150 | |
| 151 | # in case FSTRING_START was already emitted |
| 152 | if last_emitted and start <= last_emitted.span.start: |
| 153 | trace("before last emitted = {s}", s=start) |
| 154 | start = last_emitted.span.end + 1 |
| 155 | |
| 156 | span = Span(start, end) |
| 157 | trace("yielding span {a} -> {b}", a=span.start, b=span.end) |
| 158 | yield ColorSpan(span, "string") |
| 159 | else: |
| 160 | trace( |
| 161 | "unhandled token error({buffer}) = {te}", |
| 162 | buffer=repr(buffer), |
| 163 | te=str(exc), |
| 164 | ) |
| 165 | |
| 166 | |
| 167 | def gen_colors_from_token_stream( |
no test coverage detected
searching dependent graphs…