Skip to content

Commit 081f932

Browse files
committed
py/lexer: Raise NotImplError for unicode name escape, instead of assert.
1 parent a7ffa97 commit 081f932

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

py/lexer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "py/mpstate.h"
3131
#include "py/lexer.h"
32+
#include "py/runtime.h"
3233

3334
#define TAB_SIZE (8)
3435

@@ -466,7 +467,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
466467
// 3MB of text; even gzip-compressed and with minimal structure, it'll take
467468
// roughly half a meg of storage. This form of Unicode escape may be added
468469
// later on, but it's definitely not a priority right now. -- CJA 20140607
469-
assert(!"Unicode name escapes not supported");
470+
mp_not_implemented("unicode name escapes");
470471
break;
471472
default:
472473
if (c >= '0' && c <= '7') {

tests/misc/non_compliant_lexer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# lexer tests for things that are not implemented, or have non-compliant behaviour
22

3+
def test(code):
4+
try:
5+
exec(code)
6+
print('no Error')
7+
except SyntaxError:
8+
print('SyntaxError')
9+
except NotImplementedError:
10+
print('NotImplementedError')
11+
312
# uPy requires spaces between literal numbers and keywords, CPy doesn't
413
try:
514
eval('1and 0')
@@ -17,3 +26,6 @@
1726
eval('1if 0else 0')
1827
except SyntaxError:
1928
print('SyntaxError')
29+
30+
# unicode name escapes are not implemented
31+
test('"\\N{LATIN SMALL LETTER A}"')

tests/misc/non_compliant_lexer.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ SyntaxError
22
SyntaxError
33
SyntaxError
44
SyntaxError
5+
NotImplementedError

0 commit comments

Comments
 (0)