def do_escape(source, n):
if not n + <NUM_LIT:1> < len(source):<EOL><INDENT>return '<STR_LIT>'  <EOL><DEDENT>if source[n + <NUM_LIT:1>] in LINE_TERMINATOR:<EOL><INDENT>if source[n + <NUM_LIT:1>] == CR and n + <NUM_LIT:2> < len(source) and source[n + <NUM_LIT:2>] == LF:<EOL><INDENT>return source[n:n + <NUM_LIT:3>], n + <NUM_LIT:3><EOL><DEDENT>return source[n:n + <NUM_LIT:2>], n + <NUM_LIT:2><EOL><DEDENT>if source[n + <NUM_LIT:1>] in ESCAPE_CHARS:<EOL><INDENT>return source[n:n + <NUM_LIT:2>], n + <NUM_LIT:2><EOL><DEDENT>if source[n + <NUM_LIT:1>] in {'<STR_LIT:x>', '<STR_LIT:u>'}:<EOL><INDENT>char, length = ('<STR_LIT:u>', <NUM_LIT:4>) if source[n + <NUM_LIT:1>] == '<STR_LIT:u>' else ('<STR_LIT:x>', <NUM_LIT:2>)<EOL>n += <NUM_LIT:2><EOL>end = parse_num(source, n, HEX)<EOL>if end - n < length:<EOL><INDENT>raise SyntaxError('<STR_LIT>')<EOL><DEDENT>return source[n - <NUM_LIT:2>:n + length], n + length<EOL><DEDENT>if source[n + <NUM_LIT:1>] in OCTAL:<EOL><INDENT>n += <NUM_LIT:1><EOL>end = parse_num(source, n, OCTAL)<EOL>end = min(end, n + <NUM_LIT:3>)  <EOL>max_num = <NUM_LIT:255><EOL>num = <NUM_LIT:0><EOL>len_parsed = <NUM_LIT:0><EOL>for e in source[n:end]:<EOL><INDENT>cand = <NUM_LIT:8> * num + int(e)<EOL>if cand > max_num:<EOL><INDENT>break<EOL><DEDENT>num = cand<EOL>len_parsed += <NUM_LIT:1><EOL><DEDENT>return '<STR_LIT:\\>' + hex(num)[<NUM_LIT:1>:], n + len_parsed<EOL><DEDENT>return source[n + <NUM_LIT:1>], n + <NUM_LIT:2><EOL>
Its actually quite complicated to cover every case :)
       http://www.javascriptkit.com/jsref/escapesequence.shtml