diff options
author | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-08-28 22:41:52 +0900 |
---|---|---|
committer | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-08-28 22:41:52 +0900 |
commit | f190de75cdcee9a3b88673a615b56bb72527b0c7 (patch) | |
tree | 89a8c3425c14d48d180b7e269dcbe1e21f5e1265 /sphinx/pycode/pgen2/tokenize.py | |
parent | 13bbf44d878dd2eb05b2a040d5645bd2b718d619 (diff) | |
download | sphinx-git-f190de75cdcee9a3b88673a615b56bb72527b0c7.tar.gz |
Fix: pgen2 tokenizer doesn't recognize `...` literal (Ellipsis for py3). Closes #1547
I think pgen2 code derived from lib2to3 package. Basically, the package only support python2 code then it doesn't recognize `...` literal.
Diffstat (limited to 'sphinx/pycode/pgen2/tokenize.py')
-rw-r--r-- | sphinx/pycode/pgen2/tokenize.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/pycode/pgen2/tokenize.py b/sphinx/pycode/pgen2/tokenize.py index f516f78ba..d62535050 100644 --- a/sphinx/pycode/pgen2/tokenize.py +++ b/sphinx/pycode/pgen2/tokenize.py @@ -33,6 +33,7 @@ __credits__ = \ '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 @@ -84,6 +85,9 @@ Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=", 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) @@ -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 @@ -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) |