mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Make ELLIPSIS a separate token. This makes it a syntax error to write ". . ." for Ellipsis.
This commit is contained in:
parent
428f0641ec
commit
dde002899d
9 changed files with 111 additions and 95 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue