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(): ...@@ -61,7 +61,9 @@ def make_lexicon():
two_oct = octdigit + octdigit two_oct = octdigit + octdigit
three_oct = octdigit + octdigit + octdigit three_oct = octdigit + octdigit + octdigit
two_hex = hexdigit + hexdigit 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("([{") bra = Any("([{")
ket = Any(")]}") ket = Any(")]}")
......
...@@ -565,11 +565,18 @@ def p_string_literal(s): ...@@ -565,11 +565,18 @@ def p_string_literal(s):
c = systr[1] c = systr[1]
if c in "'\"\\abfnrtv01234567": if c in "'\"\\abfnrtv01234567":
chars.append(systr) chars.append(systr)
elif c == 'x':
chars.append('\\x0' + systr[2:])
elif c == '\n': elif c == '\n':
pass 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) chars.append(systr)
else: else:
chars.append(r'\\' + systr[1:]) chars.append(r'\\' + systr[1:])
...@@ -585,8 +592,6 @@ def p_string_literal(s): ...@@ -585,8 +592,6 @@ def p_string_literal(s):
(sy, s.systring)) (sy, s.systring))
s.next() s.next()
value = ''.join(chars) value = ''.join(chars)
if kind == 'u':
value = value.decode('raw_unicode_escape')
#print "p_string_literal: value =", repr(value) ### #print "p_string_literal: value =", repr(value) ###
return kind, 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