mirror of
https://github.com/python/cpython.git
synced 2025-09-13 12:17:24 +00:00
Finished backporting PEP 3127, Integer Literal Support and Syntax.
Added 0b and 0o literals to tokenizer. Modified PyOS_strtoul to support 0b and 0o inputs. Modified PyLong_FromString to support guessing 0b and 0o inputs. Renamed test_hexoct.py to test_int_literal.py and added binary tests. Added upper and lower case 0b, 0O, and 0X tests to test_int_literal.py
This commit is contained in:
parent
7cfbf0c421
commit
9ff19b5434
7 changed files with 336 additions and 125 deletions
|
@ -1335,7 +1335,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
|
|||
/* Number */
|
||||
if (isdigit(c)) {
|
||||
if (c == '0') {
|
||||
/* Hex or octal -- maybe. */
|
||||
/* Hex, octal or binary -- maybe. */
|
||||
c = tok_nextc(tok);
|
||||
if (c == '.')
|
||||
goto fraction;
|
||||
|
@ -1356,6 +1356,30 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
|
|||
c = tok_nextc(tok);
|
||||
} while (isxdigit(c));
|
||||
}
|
||||
else if (c == 'o' || c == 'O') {
|
||||
/* Octal */
|
||||
c = tok_nextc(tok);
|
||||
if (c < '0' || c > '8') {
|
||||
tok->done = E_TOKEN;
|
||||
tok_backup(tok, c);
|
||||
return ERRORTOKEN;
|
||||
}
|
||||
do {
|
||||
c = tok_nextc(tok);
|
||||
} while ('0' <= c && c < '8');
|
||||
}
|
||||
else if (c == 'b' || c == 'B') {
|
||||
/* Binary */
|
||||
c = tok_nextc(tok);
|
||||
if (c != '0' && c != '1') {
|
||||
tok->done = E_TOKEN;
|
||||
tok_backup(tok, c);
|
||||
return ERRORTOKEN;
|
||||
}
|
||||
do {
|
||||
c = tok_nextc(tok);
|
||||
} while (c == '0' || c == '1');
|
||||
}
|
||||
else {
|
||||
int found_decimal = 0;
|
||||
/* Octal; c is first char of it */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue