Commit a7bd92e2 authored by Stefan Behnel's avatar Stefan Behnel

fixes for escape sequences in unicode literals

parent 33c9c463
......@@ -61,7 +61,9 @@ def make_lexicon():
two_oct = octdigit + octdigit
three_oct = octdigit + octdigit + octdigit
two_hex = hexdigit + hexdigit
escapeseq = Str("\\") + (two_oct | three_oct | two_hex | AnyChar)
four_hex = two_hex + two_hex
escapeseq = Str("\\") + (two_oct | three_oct | two_hex |
Str('u') + four_hex | Str('x') + two_hex | AnyChar)
bra = Any("([{")
ket = Any(")]}")
......
......@@ -565,11 +565,18 @@ def p_string_literal(s):
c = systr[1]
if c in "'\"\\abfnrtv01234567":
chars.append(systr)
elif c == 'x':
chars.append('\\x0' + systr[2:])
elif c == '\n':
pass
elif c == 'u':
elif c in 'ux':
if kind == 'u':
try:
chars.append(systr.decode('unicode_escape'))
except UnicodeDecodeError:
s.error("Invalid unicode escape '%s'" % systr,
pos = pos)
elif c == 'x':
chars.append('\\x0' + systr[2:])
else:
chars.append(systr)
else:
chars.append(r'\\' + systr[1:])
......@@ -585,8 +592,6 @@ def p_string_literal(s):
(sy, s.systring))
s.next()
value = ''.join(chars)
if kind == 'u':
value = value.decode('raw_unicode_escape')
#print "p_string_literal: value =", repr(value) ###
return kind, value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment