(src: str, pos: Pos, *, literal: bool)
| 598 | |
| 599 | |
| 600 | def parse_multiline_str(src: str, pos: Pos, *, literal: bool) -> tuple[Pos, str]: |
| 601 | pos += 3 |
| 602 | if src.startswith("\n", pos): |
| 603 | pos += 1 |
| 604 | |
| 605 | if literal: |
| 606 | delim = "'" |
| 607 | end_pos = skip_until( |
| 608 | src, |
| 609 | pos, |
| 610 | "'''", |
| 611 | error_on=ILLEGAL_MULTILINE_LITERAL_STR_CHARS, |
| 612 | error_on_eof=True, |
| 613 | ) |
| 614 | result = src[pos:end_pos] |
| 615 | pos = end_pos + 3 |
| 616 | else: |
| 617 | delim = '"' |
| 618 | pos, result = parse_basic_str(src, pos, multiline=True) |
| 619 | |
| 620 | # Add at maximum two extra apostrophes/quotes if the end sequence |
| 621 | # is 4 or 5 chars long instead of just 3. |
| 622 | if not src.startswith(delim, pos): |
| 623 | return pos, result |
| 624 | pos += 1 |
| 625 | if not src.startswith(delim, pos): |
| 626 | return pos, result + delim |
| 627 | pos += 1 |
| 628 | return pos, result + (delim * 2) |
| 629 | |
| 630 | |
| 631 | def parse_basic_str(src: str, pos: Pos, *, multiline: bool) -> tuple[Pos, str]: |
no test coverage detected