code: def loads(
      s: str, /, *, parse_float: ParseFloat = float
  ) -> dict[str, Any]:  # noqa: C901
      """Parse TOML from a string."""
  
      # The spec allows converting "\r\n" to "\n", even in string
      # literals. Let's do so to simplify parsing.
      src = s.replace("\r\n", "\n")
      pos = 0
      out = Output(NestedDict(), Flags())
      header: Key = ()
      parse_float = make_safe_parse_float(parse_float)
  
      # Parse one statement at a time
      # (typically means one line in TOML source)
      while True:
          # 1. Skip line leading whitespace
          pos = skip_chars(src, pos, TOML_WS)
  
          # 2. Parse rules. Expect one of the following:
          #    - end of file
          #    - end of line
          #    - comment
          #    - key/value pair
          #    - append dict to list (and move to its namespace)
          #    - create dict (and move to its namespace)
          # Skip trailing whitespace when applicable.
          try:
              char = src[pos]
          except IndexError:
              break
          if char == "\n":
              pos += 1
              continue
          if char in KEY_INITIAL_CHARS:
              pos = key_value_rule(src, pos, out, header, parse_float)
              pos = skip_chars(src, pos, TOML_WS)
          elif char == "[":
              try:
                  second_char: str | None = src[pos + 1]
              except IndexError:
                  second_char = None
              out.flags.finalize_pending()
              if second_char == "[":
                  pos, header = create_list_rule(src, pos, out)
              else:
                  pos, header = create_dict_rule(src, pos, out)
              pos = skip_chars(src, pos, TOML_WS)
          elif char != "#":
              raise suffixed_err(src, pos, "Invalid statement")
  
          # 3. Skip comment
          pos = skip_comment(src, pos)
  
          # 4. Expect end of line or end of file
          try:
              char = src[pos]
          except IndexError:
              break
          if char != "\n":
              raise suffixed_err(
                  src,
                  pos,
                  "Expected newline or end of document after a statement",
              )
          pos += 1
  
      return out.data.dict
  
imports: from __future__ import annotations
  from collections.abc import Iterable
  import string
  from types import MappingProxyType
  from typing import Any, BinaryIO, NamedTuple
  from ._re import RE_DATETIME, RE_LOCALTIME, RE_NUMBER, match_to_datetime, match_to_localtime, match_to_number
  from ._types import Key, ParseFloat, Pos
label_desc: Use image node_id 2 for calling a global function with example usage: loads() and returns: out