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(")]}")
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':
- chars.append(systr)
+ 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:])
elif sy == 'NEWLINE':
(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