Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5dc5e3

Browse files
committed
Added support for imaginary constants (e.g. 0j, 1j, 1.0j).
1 parent c43b685 commit b5dc5e3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Lib/tokenize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
"""
1616

17-
__version__ = "Ka-Ping Yee, 4 March 1997, updated by GvR, 6 March 1997"
17+
__version__ = "Ka-Ping Yee, 4 March 1997, updated by GvR, 10 March 1997"
1818

1919
import string, regex
2020
from token import *
@@ -24,14 +24,15 @@ def group(*choices): return '\(' + string.join(choices, '\|') + '\)'
2424
Ignore = '[ \f\t]*\([\]\r?\n[ \t]*\)*\(#.*\)?'
2525
Name = '[a-zA-Z_][a-zA-Z0-9_]*'
2626

27+
ImagZero = '0[jJ]' # This is not caught by any of the following
2728
Hexnumber = '0[xX][0-9a-fA-F]*[lL]?'
2829
Octnumber = '0[0-7]*[lL]?'
29-
Decnumber = '[1-9][0-9]*[lL]?'
30-
Intnumber = group(Hexnumber, Octnumber, Decnumber)
30+
Decnumber = '[1-9][0-9]*[lLjJ]?'
31+
Intnumber = group(ImagZero, Hexnumber, Octnumber, Decnumber)
3132
Exponent = '[eE][-+]?[0-9]+'
3233
Pointfloat = group('[0-9]+\.[0-9]*', '\.[0-9]+') + group(Exponent) + '?'
3334
Expfloat = '[0-9]+' + Exponent
34-
Floatnumber = group(Pointfloat, Expfloat)
35+
Floatnumber = group(Pointfloat, Expfloat) + "[jJ]?"
3536
Number = group(Floatnumber, Intnumber)
3637

3738
Single = group('^\'', '[^\]\'')

0 commit comments

Comments
 (0)