@@ -502,19 +502,32 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
502502 case 'v' : c = 0x0b ; break ;
503503 case 'f' : c = 0x0c ; break ;
504504 case 'r' : c = 0x0d ; break ;
505+ case 'u' :
506+ case 'U' :
507+ if (is_bytes ) {
508+ // b'\u1234' == b'\\u1234'
509+ vstr_add_char (& lex -> vstr , '\\' );
510+ break ;
511+ }
512+ // Otherwise fall through.
505513 case 'x' :
506514 {
507515 uint num = 0 ;
508- if (!get_hex (lex , 2 , & num )) {
516+ if (!get_hex (lex , ( c == 'x' ? 2 : c == 'u' ? 4 : 8 ) , & num )) {
509517 // TODO error message
510518 assert (0 );
511519 }
512520 c = num ;
513521 break ;
514522 }
515- case 'N' : break ; // TODO \N{name} only in strings
516- case 'u' : break ; // TODO \uxxxx only in strings
517- case 'U' : break ; // TODO \Uxxxxxxxx only in strings
523+ case 'N' :
524+ // Supporting '\N{LATIN SMALL LETTER A}' == 'a' would require keeping the
525+ // entire Unicode name table in the core. As of Unicode 6.3.0, that's nearly
526+ // 3MB of text; even gzip-compressed and with minimal structure, it'll take
527+ // roughly half a meg of storage. This form of Unicode escape may be added
528+ // later on, but it's definitely not a priority right now. -- CJA 20140607
529+ assert (!"Unicode name escapes not supported" );
530+ break ;
518531 default :
519532 if (c >= '0' && c <= '7' ) {
520533 // Octal sequence, 1-3 chars
@@ -533,7 +546,13 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
533546 }
534547 }
535548 if (c != MP_LEXER_CHAR_EOF ) {
536- vstr_add_char (& lex -> vstr , c );
549+ if (c < 0x110000 && !is_bytes ) {
550+ vstr_add_char (& lex -> vstr , c );
551+ } else if (c < 0x100 && is_bytes ) {
552+ vstr_add_byte (& lex -> vstr , c );
553+ } else {
554+ assert (!"TODO: Throw an error, invalid escape code probably" );
555+ }
537556 }
538557 } else {
539558 vstr_add_char (& lex -> vstr , CUR_CHAR (lex ));
0 commit comments