Skip to content

Commit

Permalink
Fix: pgen2 tokenizer doesn't recognize ... literal (Ellipsis for py…
Browse files Browse the repository at this point in the history
…3). Closes #1547

I think pgen2 code derived from lib2to3 package. Basically, the package only support python2 code then it doesn't recognize `...` literal.
  • Loading branch information
shimizukawa committed Aug 28, 2014
1 parent 13bbf44 commit f190de7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Bugs fixed
:rst:dir:`c:function`. Thanks to Takeshi Komiya.
* PR#278: Fix section entries were shown twice if toctree has been put under
only directive. Thanks to Takeshi Komiya.
* #1547: pgen2 tokenizer doesn't recognize `...` literal (Ellipsis for py3).

Documentation
-------------
Expand Down
11 changes: 9 additions & 2 deletions sphinx/pycode/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro'

import string, re
from six import PY3
from sphinx.pycode.pgen2.token import *
from sphinx.pycode.pgen2 import token

Expand Down Expand Up @@ -84,6 +85,9 @@ def maybe(*choices): return group(*choices) + '?'

Bracket = '[][(){}]'
Special = group(r'\r?\n', r'[:;.,`@]')
if PY3:
Ellipsis_ = r'\.{3}'
Special = group(Ellipsis_, Special)
Funny = group(Operator, Bracket, Special)

PlainToken = group(Number, Funny, String, Name)
Expand Down Expand Up @@ -356,8 +360,9 @@ def generate_tokens(readline):
spos, epos, pos = (lnum, start), (lnum, end), end
token, initial = line[start:end], line[start]

if initial in numchars or \
(initial == '.' and token != '.'): # ordinary number
if initial in numchars or (
initial == '.' and token not in ('.', '...')
): # ordinary number
yield (NUMBER, token, spos, epos, line)
elif initial in '\r\n':
newline = NEWLINE
Expand Down Expand Up @@ -393,6 +398,8 @@ def generate_tokens(readline):
yield (STRING, token, spos, epos, line)
elif initial in namechars: # ordinary name
yield (NAME, token, spos, epos, line)
elif token in ('...',): # ordinary name
yield (NAME, token, spos, epos, line)
elif initial == '\\': # continued stmt
# This yield is new; needed for better idempotency:
yield (NL, token, spos, (lnum, pos), line)
Expand Down

0 comments on commit f190de7

Please sign in to comment.