import re


def mark_quoted_strings(sql):
    """Mark all quoted strings in the SOQL by '@' and get them as params,
    with respect to all escaped backslashes and quotes.
    """
    pm_pattern = re.compile(r"'[^\\']*(?:\\[\\'][^\\']*)*'")
    bs_pattern = re.compile(r"\\([\\'])")
    out_pattern = re.compile("^[-!()*+,.:<=>\w\s]*$")
    start = 0
    out = []
    params = []
    for match in pm_pattern.finditer(sql):
        out.append(sql[start:match.start()])
        assert out_pattern.match(sql[start:match.start()])
        params.append(bs_pattern.sub('\\1', sql[match.start() + 1:match.end() -1]))
        start = match.end()
    out.append(sql[start:])
    assert out_pattern.match(sql[start:])
    return '@'.join(out), params