def read_string(form):
    """Read a string."""
    if len(form) == 0:
        raise SyntaxError('unexpected EOF while reading string')
    if form[0] != '"':
        raise SyntaxError('expected ( as first char of string: ' + form)
    form = form[1:]
    s = ""
    escaped = False
    while len(form) > 0:
        ch = form[0]
        if ch == '"' and not escaped:
            return (s, form[1:])
        elif escaped:
            escaped = False
            s = s[:-1]  # remove the escaping backslash
        elif ch == "\\":
            escaped = True
        s = s + ch
        form = form[1:]
    raise SyntaxError('EOF while reading string')
dataset/ETHPy150Open ensime/ensime-sublime/sexp.py/read_string/original