[pypy-commit] lang-scheme default: Fix strings: Allow escaped backslash
boemmels
noreply at buildbot.pypy.org
Tue Sep 6 22:59:02 CEST 2011
Author: Juergen Boemmels <boemmels at web.de>
Branch:
Changeset: r7:0e79d2ada637
Date: 2011-09-06 22:58 +0200
http://bitbucket.org/pypy/lang-scheme/changeset/0e79d2ada637/
Log: Fix strings: Allow escaped backslash
diff --git a/scheme/ssparser.py b/scheme/ssparser.py
--- a/scheme/ssparser.py
+++ b/scheme/ssparser.py
@@ -2,18 +2,25 @@
from pypy.rlib.parsing.makepackrat import BacktrackException, Status
from scheme.object import W_Pair, W_Integer, W_String, symbol, \
w_nil, W_Boolean, W_Real, quote, qq, unquote, unquote_splicing, \
- w_ellipsis
+ w_ellipsis, SchemeSyntaxError
def str_unquote(s):
str_lst = []
- last_ch = ''
- for c in s[1:]:
- if last_ch == '\\' and c == '"':
- pass
+ pos = 1
+ last = len(s)-1
+ while pos < last:
+ ch = s[pos]
+ if ch == '\\':
+ pos += 1
+ ch = s[pos]
+ if ch == '\\' or ch == '\"':
+ str_lst.append(ch)
+ else:
+ raise SchemeSyntaxError
else:
- str_lst.append(last_ch)
+ str_lst.append(ch)
- last_ch = c
+ pos += 1
return ''.join(str_lst)
diff --git a/scheme/test/test_parser.py b/scheme/test/test_parser.py
--- a/scheme/test/test_parser.py
+++ b/scheme/test/test_parser.py
@@ -62,6 +62,16 @@
assert isinstance(t, W_String)
assert unwrap(t) == 'don\'t believe "them"'
+ more_strings = [(r'''"simple string"''', r'''simple string'''),
+ (r'''"\\ backslash"''', r'''\ backslash'''),
+ (r'''"\\\\"''',r'''\\'''),
+ (r'''"with \"quotes\""''', r'''with "quotes"'''),
+ ]
+ for code, contents in more_strings:
+ w_string = parse_sexpr(code)
+ assert isinstance(w_string, W_String)
+ assert unwrap(w_string) == contents
+
def test_objects():
w_fixnum = parse_sexpr('-12345')
assert isinstance(w_fixnum, W_Integer)
More information about the pypy-commit
mailing list