Make ELLIPSIS a separate token. This makes it a syntax error to write ". . ." for Ellipsis.

This commit is contained in:
Georg Brandl 2007-03-18 19:01:53 +00:00
parent 428f0641ec
commit dde002899d
9 changed files with 111 additions and 95 deletions

View file

@ -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 */