]> granicus.if.org Git - python/commitdiff
provide less mysterious error messages when seeing end-of-line in
authorSkip Montanaro <skip@pobox.com>
Thu, 15 Aug 2002 01:20:16 +0000 (01:20 +0000)
committerSkip Montanaro <skip@pobox.com>
Thu, 15 Aug 2002 01:20:16 +0000 (01:20 +0000)
single-quoted strings or end-of-file in triple-quoted strings.
closes patch 586561.

Include/errcode.h
Parser/tokenizer.c
Python/pythonrun.c

index a8b1aaab6f7a06e9f7d7230daca17e2d979e216f..985911eea4fbac879d74989d0244fc317832ef00 100644 (file)
@@ -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
 }
index 64ff320d65fb11de779293753b69e1f8a35ee693..7e7a37025ca763f041369de912e6541f9814b868 100644 (file)
@@ -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;
                        }
@@ -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;
                                }
index 006ff083d252746b5f73fd526885afeda5b9c11d..28a8e28e118bd217016a7c5460b69cf76047ae8e 100644 (file)
@@ -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);