py/repl: Check for an identifier char after the keyword.

- As described in the #1850.
- Add cmdline tests.
This commit is contained in:
Alex March 2016-02-16 13:36:18 +00:00 committed by Damien George
parent dfc35afba1
commit 69d9e7d27d
5 changed files with 11 additions and 5 deletions

View File

@ -123,6 +123,7 @@ bool unichar_isalpha(unichar c);
bool unichar_isprint(unichar c); bool unichar_isprint(unichar c);
bool unichar_isdigit(unichar c); bool unichar_isdigit(unichar c);
bool unichar_isxdigit(unichar c); bool unichar_isxdigit(unichar c);
bool unichar_isident(unichar c);
bool unichar_isupper(unichar c); bool unichar_isupper(unichar c);
bool unichar_islower(unichar c); bool unichar_islower(unichar c);
unichar unichar_tolower(unichar c); unichar unichar_tolower(unichar c);

View File

@ -38,7 +38,7 @@ STATIC bool str_startswith_word(const char *str, const char *head) {
return false; return false;
} }
} }
return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i])); return head[i] == '\0' && (str[i] == '\0' || !unichar_isident(str[i]));
} }
bool mp_repl_continue_with_input(const char *input) { bool mp_repl_continue_with_input(const char *input) {

View File

@ -145,11 +145,9 @@ bool unichar_isxdigit(unichar c) {
return c < 128 && (attr[c] & FL_XDIGIT) != 0; return c < 128 && (attr[c] & FL_XDIGIT) != 0;
} }
/* bool unichar_isident(unichar c) {
bool unichar_is_alpha_or_digit(unichar c) { return c < 128 && ((attr[c] & (FL_ALPHA | FL_DIGIT)) != 0 || c == '_');
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
} }
*/
bool unichar_isupper(unichar c) { bool unichar_isupper(unichar c) {
return c < 128 && (attr[c] & FL_UPPER) != 0; return c < 128 && (attr[c] & FL_UPPER) != 0;

View File

@ -29,3 +29,6 @@ def f(x):
print(x) print(x)
 
f(3) f(3)
if1=1
if1 = 2
print(if1)

View File

@ -50,4 +50,8 @@ two
...  ... 
>>> f(3) >>> f(3)
3 3
>>> if1=1
>>> if1 = 2
>>> print(if1)
2
>>> >>>