Skip to content

Commit

Permalink
provide less mysterious error messages when seeing end-of-line in
Browse files Browse the repository at this point in the history
single-quoted strings or end-of-file in triple-quoted strings.
closes patch 586561.
  • Loading branch information
Skip Montanaro committed Aug 15, 2002
1 parent 90e9a79 commit 118ec70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Include/errcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern "C" {
#define E_TOODEEP 20 /* Too many indentation levels */
#define E_DEDENT 21 /* No matching outer block for dedent */
#define E_DECODE 22 /* Error in decoding into Unicode */
#define E_EOFS 23 /* EOF in triple-quoted string */
#define E_EOLS 24 /* EOL in single-quoted string */

#ifdef __cplusplus
}
Expand Down
9 changes: 6 additions & 3 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,14 +1276,17 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
c = tok_nextc(tok);
if (c == '\n') {
if (!triple) {
tok->done = E_TOKEN;
tok->done = E_EOLS;
tok_backup(tok, c);
return ERRORTOKEN;
}
tripcount = 0;
}
else if (c == EOF) {
tok->done = E_TOKEN;
if (triple)
tok->done = E_EOFS;
else
tok->done = E_EOLS;
tok->cur = tok->inp;
return ERRORTOKEN;
}
Expand All @@ -1305,7 +1308,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
tripcount = 0;
c = tok_nextc(tok);
if (c == EOF) {
tok->done = E_TOKEN;
tok->done = E_EOLS;
tok->cur = tok->inp;
return ERRORTOKEN;
}
Expand Down
6 changes: 6 additions & 0 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,12 @@ err_input(perrdetail *err)
case E_TOKEN:
msg = "invalid token";
break;
case E_EOFS:
msg = "EOF while scanning triple-quoted string";
break;
case E_EOLS:
msg = "EOL while scanning single-quoted string";
break;
case E_INTR:
PyErr_SetNone(PyExc_KeyboardInterrupt);
Py_XDECREF(v);
Expand Down

0 comments on commit 118ec70

Please sign in to comment.