Skip to content

Commit 69d9e7d

Browse files
Alex Marchdpgeorge
authored andcommitted
py/repl: Check for an identifier char after the keyword.
- As described in the adafruit#1850. - Add cmdline tests.
1 parent dfc35af commit 69d9e7d

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

py/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool unichar_isalpha(unichar c);
123123
bool unichar_isprint(unichar c);
124124
bool unichar_isdigit(unichar c);
125125
bool unichar_isxdigit(unichar c);
126+
bool unichar_isident(unichar c);
126127
bool unichar_isupper(unichar c);
127128
bool unichar_islower(unichar c);
128129
unichar unichar_tolower(unichar c);

py/repl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ STATIC bool str_startswith_word(const char *str, const char *head) {
3838
return false;
3939
}
4040
}
41-
return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i]));
41+
return head[i] == '\0' && (str[i] == '\0' || !unichar_isident(str[i]));
4242
}
4343

4444
bool mp_repl_continue_with_input(const char *input) {

py/unicode.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ bool unichar_isxdigit(unichar c) {
145145
return c < 128 && (attr[c] & FL_XDIGIT) != 0;
146146
}
147147

148-
/*
149-
bool unichar_is_alpha_or_digit(unichar c) {
150-
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
148+
bool unichar_isident(unichar c) {
149+
return c < 128 && ((attr[c] & (FL_ALPHA | FL_DIGIT)) != 0 || c == '_');
151150
}
152-
*/
153151

154152
bool unichar_isupper(unichar c) {
155153
return c < 128 && (attr[c] & FL_UPPER) != 0;

tests/cmdline/repl_cont.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ def f(x):
2929
print(x)
3030

3131
f(3)
32+
if1=1
33+
if1 = 2
34+
print(if1)

tests/cmdline/repl_cont.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ two
5050
... 
5151
>>> f(3)
5252
3
53+
>>> if1=1
54+
>>> if1 = 2
55+
>>> print(if1)
56+
2
5357
>>>

0 commit comments

Comments
 (0)