MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_value

Function parse_value

Lib/tomllib/_parser.py:663–728  ·  view source on GitHub ↗
(  # noqa: C901
    src: str, pos: Pos, parse_float: ParseFloat
)

Source from the content-addressed store, hash-verified

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

Callers 2

parse_key_value_pairFunction · 0.85
parse_arrayFunction · 0.85

Calls 12

parse_multiline_strFunction · 0.85
parse_one_line_basic_strFunction · 0.85
parse_literal_strFunction · 0.85
parse_arrayFunction · 0.85
parse_inline_tableFunction · 0.85
match_to_datetimeFunction · 0.85
TOMLDecodeErrorClass · 0.85
match_to_localtimeFunction · 0.85
match_to_numberFunction · 0.85
startswithMethod · 0.45
matchMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected