summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-18 19:01:53 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-18 19:01:53 (GMT)
commitdde002899db8d04ac25d630fcc3a27e8bbf282ea (patch)
tree336d26b7a0e0da705cc729688de862bea896b251 /Lib
parent428f0641ec34902b0cce2cfdca833c79e6fdab7c (diff)
downloadcpython-dde002899db8d04ac25d630fcc3a27e8bbf282ea.zip
cpython-dde002899db8d04ac25d630fcc3a27e8bbf282ea.tar.gz
cpython-dde002899db8d04ac25d630fcc3a27e8bbf282ea.tar.bz2
Make ELLIPSIS a separate token. This makes it a syntax error to write ". . ." for Ellipsis.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/compiler/transformer.py2
-rw-r--r--Lib/test/test_grammar.py1
-rwxr-xr-xLib/token.py7
-rw-r--r--Lib/tokenize.py6
4 files changed, 9 insertions, 7 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 79b702c..f07ec97 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -113,7 +113,7 @@ class Transformer:
token.LBRACE: self.atom_lbrace,
token.NUMBER: self.atom_number,
token.STRING: self.atom_string,
- token.DOT: self.atom_ellipsis,
+ token.ELLIPSIS: self.atom_ellipsis,
token.NAME: self.atom_name,
}
self.encoding = None
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 1a14756..bd80db6 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -121,6 +121,7 @@ the \'lazy\' dog.\n\
def testEllipsis(self):
x = ...
self.assert_(x is Ellipsis)
+ self.assertRaises(SyntaxError, eval, ".. .")
class GrammarTests(unittest.TestCase):
diff --git a/Lib/token.py b/Lib/token.py
index 147536c..eb48e76 100755
--- a/Lib/token.py
+++ b/Lib/token.py
@@ -61,9 +61,10 @@ DOUBLESLASH = 48
DOUBLESLASHEQUAL = 49
AT = 50
RARROW = 51
-OP = 52
-ERRORTOKEN = 53
-N_TOKENS = 54
+ELLIPSIS = 52
+OP = 53
+ERRORTOKEN = 54
+N_TOKENS = 55
NT_OFFSET = 256
#--end constants--
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index e502da9..cda82ca 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -83,7 +83,7 @@ Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=",
r"~")
Bracket = '[][(){}]'
-Special = group(r'\r?\n', r'[:;.,@]')
+Special = group(r'\r?\n', r'\.\.\.', r'[:;.,@]')
Funny = group(Operator, Bracket, Special)
PlainToken = group(Number, Funny, String, Name)
@@ -334,8 +334,8 @@ 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 # ordinary number
+ (initial == '.' and token != '.' and token != '...')):
yield (NUMBER, token, spos, epos, line)
elif initial in '\r\n':
yield (NL if parenlev > 0 else NEWLINE,