summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
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 /Parser/tokenizer.c
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 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 84bd60e..ec3c5db 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -93,6 +93,7 @@ char *_PyParser_TokenNames[] = {
"DOUBLESLASHEQUAL",
"AT",
"RARROW",
+ "ELLIPSIS",
/* This table must match the #defines in token.h! */
"OP",
"<ERRORTOKEN>",
@@ -1082,6 +1083,16 @@ PyToken_ThreeChars(int c1, int c2, int c3)
break;
}
break;
+ case '.':
+ switch (c2) {
+ case '.':
+ switch (c3) {
+ case '.':
+ return ELLIPSIS;
+ }
+ break;
+ }
+ break;
}
return OP;
}
@@ -1278,13 +1289,22 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
c = tok_nextc(tok);
if (isdigit(c)) {
goto fraction;
- }
- else {
+ } else if (c == '.') {
+ c = tok_nextc(tok);
+ if (c == '.') {
+ *p_start = tok->start;
+ *p_end = tok->cur;
+ return ELLIPSIS;
+ } else {
+ tok_backup(tok, c);
+ }
+ tok_backup(tok, '.');
+ } else {
tok_backup(tok, c);
- *p_start = tok->start;
- *p_end = tok->cur;
- return DOT;
}
+ *p_start = tok->start;
+ *p_end = tok->cur;
+ return DOT;
}
/* Number */