code: def as_fstring(text):
      
      for quote in ('"""', "'''"):
          # although script-format always ends with \n, direct use of this function might
          # have string ending with " or '
          if quote not in text and not text.endswith(quote[0]):
              return 'fr' + quote + text + quote
  
      # now, we need to look into the structure of f-string
      pieces = split_fstring(text)
      # if all expressions do not have single quote, we can
      # safely repr the entire string
      if not any("'" in piece for piece in pieces[1::2]):
          return 'f' + repr(text)
      #
      # unfortunately, this thing has both single and double triple quotes
      # because we cannot use backslash inside expressions in f-string, we
      # have to use format string now.
      args = []
      for idx in range(len(pieces))[1::2]:
          pos = valid_expr_till(pieces[idx])
          if pos == 0:
              raise SyntaxError(f'invalid expression in {pieces[idx]}')
          args.append(pieces[idx][:pos])
          pieces[idx] = '{' + str(idx // 2) + pieces[idx][pos:] + '}'
      return repr(''.join(pieces)) + '.format(' + ', '.join(args) + ')'
docs: expansion with python f-string, usually ok, but with the case
         of ' inside expressions, adding repr will add backslash to it
         and cause trouble.