(
src: str, pos: Pos, parse_float: ParseFloat
)
| 666 | |
| 667 | |
| 668 | def parse_value( |
| 669 | src: str, pos: Pos, parse_float: ParseFloat |
| 670 | ) -> tuple[Pos, Any]: |
| 671 | try: |
| 672 | char: str | None = src[pos] |
| 673 | except IndexError: |
| 674 | char = None |
| 675 | |
| 676 | # IMPORTANT: order conditions based on speed of checking and likelihood |
| 677 | |
| 678 | # Basic strings |
| 679 | if char == '"': |
| 680 | if src.startswith('"""', pos): |
| 681 | return parse_multiline_str(src, pos, literal=False) |
| 682 | return parse_one_line_basic_str(src, pos) |
| 683 | |
| 684 | # Literal strings |
| 685 | if char == "'": |
| 686 | if src.startswith("'''", pos): |
| 687 | return parse_multiline_str(src, pos, literal=True) |
| 688 | return parse_literal_str(src, pos) |
| 689 | |
| 690 | # Booleans |
| 691 | if char == "t": |
| 692 | if src.startswith("true", pos): |
| 693 | return pos + 4, True |
| 694 | if char == "f": |
| 695 | if src.startswith("false", pos): |
| 696 | return pos + 5, False |
| 697 | |
| 698 | # Arrays |
| 699 | if char == "[": |
| 700 | return parse_array(src, pos, parse_float) |
| 701 | |
| 702 | # Inline tables |
| 703 | if char == "{": |
| 704 | return parse_inline_table(src, pos, parse_float) |
| 705 | |
| 706 | # Dates and times |
| 707 | datetime_match = RE_DATETIME.match(src, pos) |
| 708 | if datetime_match: |
| 709 | try: |
| 710 | datetime_obj = match_to_datetime(datetime_match) |
| 711 | except ValueError as e: |
| 712 | raise TOMLDecodeError("Invalid date or datetime", src, pos) from e |
| 713 | return datetime_match.end(), datetime_obj |
| 714 | localtime_match = RE_LOCALTIME.match(src, pos) |
| 715 | if localtime_match: |
| 716 | return localtime_match.end(), match_to_localtime(localtime_match) |
| 717 | |
| 718 | # Integers and "normal" floats. |
| 719 | # The regex will greedily match any type starting with a decimal |
| 720 | # char, so needs to be located after handling of dates and times. |
| 721 | number_match = RE_NUMBER.match(src, pos) |
| 722 | if number_match: |
| 723 | return number_match.end(), match_to_number(number_match, parse_float) |
| 724 | |
| 725 | # Special floats |
no test coverage detected
searching dependent graphs…