summaryrefslogtreecommitdiff
path: root/Cython/Compiler/Lexicon.py
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2016-03-24 22:14:15 -0700
committerRobert Bradshaw <robertwb@gmail.com>2016-03-24 22:14:15 -0700
commit50e67150fa3176e22e1f47b65b7d61b0e55e5d89 (patch)
treeb631c40f27f5751774ca34f375b117e89d2f9287 /Cython/Compiler/Lexicon.py
parentfe3a65f7ef44567b4474db3c5d894a580d09e975 (diff)
parent0c03ca0dbac42fb1d5006d2e11f682a3de2a9051 (diff)
downloadcython-50e67150fa3176e22e1f47b65b7d61b0e55e5d89.tar.gz
Merge pull request #499 from cython/pep515_underscores_in_numbers
Implement PEP 515: allow underscores in number literals
Diffstat (limited to 'Cython/Compiler/Lexicon.py')
-rw-r--r--Cython/Compiler/Lexicon.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Cython/Compiler/Lexicon.py b/Cython/Compiler/Lexicon.py
index ade75dd44..df664958e 100644
--- a/Cython/Compiler/Lexicon.py
+++ b/Cython/Compiler/Lexicon.py
@@ -26,15 +26,18 @@ def make_lexicon():
hexdigit = Any("0123456789ABCDEFabcdef")
indentation = Bol + Rep(Any(" \t"))
- decimal = Rep1(digit)
+ def underscore_digits(d):
+ return Rep1(d) + Rep(Str("_") + Rep1(d))
+
+ decimal = underscore_digits(digit)
dot = Str(".")
exponent = Any("Ee") + Opt(Any("+-")) + decimal
decimal_fract = (decimal + dot + Opt(decimal)) | (dot + decimal)
name = letter + Rep(letter | digit)
- intconst = decimal | (Str("0") + ((Any("Xx") + Rep1(hexdigit)) |
- (Any("Oo") + Rep1(octdigit)) |
- (Any("Bb") + Rep1(bindigit)) ))
+ intconst = decimal | (Str("0") + ((Any("Xx") + underscore_digits(hexdigit)) |
+ (Any("Oo") + underscore_digits(octdigit)) |
+ (Any("Bb") + underscore_digits(bindigit)) ))
intsuffix = (Opt(Any("Uu")) + Opt(Any("Ll")) + Opt(Any("Ll"))) | (Opt(Any("Ll")) + Opt(Any("Ll")) + Opt(Any("Uu")))
intliteral = intconst + intsuffix
fltconst = (decimal_fract + Opt(exponent)) | (decimal + exponent)
@@ -67,9 +70,9 @@ def make_lexicon():
return Lexicon([
(name, IDENT),
- (intliteral, 'INT'),
- (fltconst, 'FLOAT'),
- (imagconst, 'IMAG'),
+ (intliteral, Method('strip_underscores', symbol='INT')),
+ (fltconst, Method('strip_underscores', symbol='FLOAT')),
+ (imagconst, Method('strip_underscores', symbol='IMAG')),
(punct | diphthong, TEXT),
(bra, Method('open_bracket_action')),