(self, text: str)
return "".join(tokens)
r"""
        Unescape a quoted string, by looking at \ that precede a quote.

        The input string should contain enclosing quotes, which are stripped away
        by this function.

        Due to the grammar definition of quoted strings, it is assumed that:
            * if there are \ preceding the closing quote, their number must be even
            * if there are \ preceding a quote in the middle of the string, their
              number must be odd

        Examples (with double quotes, but the same logic applies to single quotes):
            * "abc\"def"    -> abc"def
            * "abc\\\"def"  -> abc\"def
            * "abc\\"       -> abc\
            * "abc\\\\"     -> abc\\"
r"""
        Unescape a quoted string, by looking at \ that precede a quote.
r Unescape a quoted string by looking at \ that precede a quote .
def _unescape_quoted_string(self, text: str) -> str:
        r"""
        Unescape a quoted string, by looking at \ that precede a quote.

        The input string should contain enclosing quotes, which are stripped away
        by this function.

        Due to the grammar definition of quoted strings, it is assumed that:
            * if there are \ preceding the closing quote, their number must be even
            * if there are \ preceding a quote in the middle of the string, their
              number must be odd

        Examples (with double quotes, but the same logic applies to single quotes):
            * "abc\"def"    -> abc"def
            * "abc\\\"def"  -> abc\"def
            * "abc\\"       -> abc\
            * "abc\\\\"     -> abc\\"
        """
        qc = text[0]  # quote character
        text = text[1:]  # remove first quote *but* keep the last one
        pattern = _ESC_QUOTED_STR[qc]
        match = pattern.search(text)

        if match is None:
            return text[0:-1]  # remove last quote

        tokens = []
        while match is not None:
            start, stop = match.span()
            # Add characters before the escaped sequence.
            tokens.append(text[0:start])
            # Un-escaping. Note that this works both for escaped quotes in the middle of
            # a string, as well as trailing backslashes where the end quote is stripped:
            #   \"    -> "  (escaped quote in the middle)
            #   \\"   -> \  (escaped trailing backslash)
            #   \\\"  -> \" (escaped backslash followed by escaped quote in the middle)
            #   \\\\" -> \\ (two escaped trailing backslashes)
            #   ...
            tokens.append(text[start + 1 : stop : 2])
            # Move on to next match.
            text = text[stop:]
            match = pattern.search(text)

        if len(text) > 1:
            # Add characters after the last match, removing the end quote.
            tokens.append(text[0:-1])

        return "".join(tokens)
def _unescape_quoted_string ( self , text : str ) -> str : qc = text [ 0 ] # quote character text = text [ 1 : ] # remove first quote *but* keep the last one pattern = _ESC_QUOTED_STR [ qc ] match = pattern . search ( text ) if match is None : return text [ 0 : - 1 ] # remove last quote tokens = [ ] while match is not None : start , stop = match . span ( ) # Add characters before the escaped sequence. tokens . append ( text [ 0 : start ] ) # Un-escaping. Note that this works both for escaped quotes in the middle of # a string, as well as trailing backslashes where the end quote is stripped: #   \"    -> "  (escaped quote in the middle) #   \\"   -> \  (escaped trailing backslash) #   \\\"  -> \" (escaped backslash followed by escaped quote in the middle) #   \\\\" -> \\ (two escaped trailing backslashes) #   ... tokens . append ( text [ start + 1 : stop : 2 ] ) # Move on to next match. text = text [ stop : ] match = pattern . search ( text ) if len ( text ) > 1 : # Add characters after the last match, removing the end quote. tokens . append ( text [ 0 : - 1 ] ) return "" . join ( tokens )