8000 bpo-29869: Allow underscores in numeric literals in lib2to3. by nevsan · Pull Request #752 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-29869: Allow underscores in numeric literals in lib2to3. #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stricter literal parsing for Python 3.6 in lib2to3.pgen2.tokenize.
  • Loading branch information
nevsan committed Mar 23, 2017
commit 2fd46ccb325c20ee22e9ac66699de8adf46c75c4
16 changes: 8 additions & 8 deletions Lib/lib2to3/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def maybe(*choices): return group(*choices) + '?'
Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment)
Name = r'[a-zA-Z_]\w*'

Binnumber = r'0[bB][01_]*'
Hexnumber = r'0[xX][\da-fA-F_]*[lL]?'
Octnumber = r'0[oO]?[0-7_]*[lL]?'
Decnumber = r'[1-9][\d_]*[lL]?'
Binnumber = r'0[bB]_?[01]+(?:_[01]+)*'
Hexnumber = r'0[xX]_?[\da-fA-F]+(?:_[\da-fA-F]+)*[lL]?'
Octnumber = r'0[oO]?_?[0-7]+(?:_[0-7]+)*[lL]?'
Decnumber = group(r'[1-9]\d*(?:_\d+)*[lL]?', '0[lL]?')
Intnumber = group(Binnumber, Hexnumber, Octnumber, Decnumber)
Exponent = r'[eE][-+]?\d+'
Pointfloat = group(r'\d+\.\d*', r'\.\d+') + maybe(Exponent)
Expfloat = r'\d+' + Exponent
Exponent = r'[eE][-+]?\d+(?:_\d+)*'
Pointfloat = group(r'\d+(?:_\d+)*\.(?:\d+(?:_\d+)*)?', r'\.\d+(?:_\d+)*') + maybe(Exponent)
Expfloat = r'\d+(?:_\d+)*' + Exponent
Floatnumber = group(Pointfloat, Expfloat)
Imagnumber = group(r'\d+[jJ]', Floatnumber + r'[jJ]')
Imagnumber = group(r'\d+(?:_\d+)*[jJ]', Floatnumber + r'[jJ]')
Number = group(Imagnumber, Floatnumber, Intnumber)

# Tail end of ' string.
Expand Down
0