( # noqa: C901
src: str, pos: Pos, parse_float: ParseFloat
)
| 582 | |
| 583 | |
| 584 | def parse_value( # noqa: C901 |
| 585 | src: str, pos: Pos, parse_float: ParseFloat |
| 586 | ) -> tuple[Pos, Any]: |
| 587 | try: |
| 588 | char: str | None = src[pos] |
| 589 | except IndexError: |
| 590 | char = None |
| 591 | |
| 592 | # IMPORTANT: order conditions based on speed of checking and likelihood |
| 593 | |
| 594 | # Basic strings |
| 595 | if char == '"': |
| 596 | if src.startswith('"""', pos): |
| 597 | return parse_multiline_str(src, pos, literal=False) |
| 598 | return parse_one_line_basic_str(src, pos) |
| 599 | |
| 600 | # Literal strings |
| 601 | if char == "'": |
| 602 | if src.startswith("'''", pos): |
| 603 | return parse_multiline_str(src, pos, literal=True) |
| 604 | return parse_literal_str(src, pos) |
| 605 | |
| 606 | # Booleans |
| 607 | if char == "t": |
| 608 | if src.startswith("true", pos): |
| 609 | return pos + 4, True |
| 610 | if char == "f": |
| 611 | if src.startswith("false", pos): |
| 612 | return pos + 5, False |
| 613 | |
| 614 | # Arrays |
| 615 | if char == "[": |
| 616 | return parse_array(src, pos, parse_float) |
| 617 | |
| 618 | # Inline tables |
| 619 | if char == "{": |
| 620 | return parse_inline_table(src, pos, parse_float) |
| 621 | |
| 622 | # Dates and times |
| 623 | datetime_match = RE_DATETIME.match(src, pos) |
| 624 | if datetime_match: |
| 625 | try: |
| 626 | datetime_obj = match_to_datetime(datetime_match) |
| 627 | except ValueError as e: |
| 628 | raise suffixed_err(src, pos, "Invalid date or datetime") from e |
| 629 | return datetime_match.end(), datetime_obj |
| 630 | localtime_match = RE_LOCALTIME.match(src, pos) |
| 631 | if localtime_match: |
| 632 | return localtime_match.end(), match_to_localtime(localtime_match) |
| 633 | |
| 634 | # Integers and "normal" floats. |
| 635 | # The regex will greedily match any type starting with a decimal |
| 636 | # char, so needs to be located after handling of dates and times. |
| 637 | number_match = RE_NUMBER.match(src, pos) |
| 638 | if number_match: |
| 639 | return number_match.end(), match_to_number(number_match, parse_float) |
| 640 | |
| 641 | # Special floats |
no test coverage detected