aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2015-09-07 17:33:44 +0100
committerDamien George2015-09-07 17:33:44 +0100
commit2b000474d9350ede1c1aedb83ba8976d81ba4cf8 (patch)
tree2e5c52a1360198dec4c4c80df0aa158e806176e3
parent0be3c70cd88da39ee4dcc328ba3bde1e5abcd406 (diff)
py/lexer: Properly classify floats that look like hex numbers.
Eg 0e0 almost looks like a hex number but in fact is a float.
-rw-r--r--py/lexer.c7
-rw-r--r--tests/float/float1.py3
2 files changed, 7 insertions, 3 deletions
diff --git a/py/lexer.c b/py/lexer.c
index c77b459eb..6bacb9fc6 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -105,8 +105,9 @@ STATIC bool is_following_digit(mp_lexer_t *lex) {
return unichar_isdigit(lex->chr1);
}
-STATIC bool is_following_letter(mp_lexer_t *lex) {
- return unichar_isalpha(lex->chr1);
+STATIC bool is_following_base_char(mp_lexer_t *lex) {
+ const unichar chr1 = lex->chr1 | 0x20;
+ return chr1 == 'b' || chr1 == 'o' || chr1 == 'x';
}
STATIC bool is_following_odigit(mp_lexer_t *lex) {
@@ -541,7 +542,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
lex->tok_kind = MP_TOKEN_FLOAT_OR_IMAG;
} else {
lex->tok_kind = MP_TOKEN_INTEGER;
- if (is_char(lex, '0') && is_following_letter(lex)) {
+ if (is_char(lex, '0') && is_following_base_char(lex)) {
forced_integer = true;
}
}
diff --git a/tests/float/float1.py b/tests/float/float1.py
index 935375c47..27fe26205 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -4,6 +4,9 @@
print(.12)
print(1.)
print(1.2)
+print(0e0)
+print(0e+0)
+print(0e-0)
# float construction
print(float(1.2))