]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Changes to accept double-quoted strings on input.
authorGuido van Rossum <guido@python.org>
Tue, 26 Oct 1993 15:19:44 +0000 (15:19 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 26 Oct 1993 15:19:44 +0000 (15:19 +0000)
Parser/tokenizer.c
Python/compile.c

index 725a2f1221b03d02cbf329b9426c8557d4b80fc9..6504e0cec87b0519b7cb4aa1f3917455e51e8d7a 100644 (file)
@@ -564,7 +564,7 @@ tok_get(tok, p_start, p_end)
                return NUMBER;
        }
        
-       /* String */
+       /* String (single quotes) */
        if (c == '\'') {
                for (;;) {
                        c = tok_nextc(tok);
@@ -590,6 +590,32 @@ tok_get(tok, p_start, p_end)
                return STRING;
        }
        
+       /* String (double quotes) */
+       if (c == '\"') {
+               for (;;) {
+                       c = tok_nextc(tok);
+                       if (c == '\n' || c == EOF) {
+                               tok->done = E_TOKEN;
+                               tok->cur = tok->inp;
+                               return ERRORTOKEN;
+                       }
+                       if (c == '\\') {
+                               c = tok_nextc(tok);
+                               *p_end = tok->cur;
+                               if (c == '\n' || c == EOF) {
+                                       tok->done = E_TOKEN;
+                                       tok->cur = tok->inp;
+                                       return ERRORTOKEN;
+                               }
+                               continue;
+                       }
+                       if (c == '\"')
+                               break;
+               }
+               *p_end = tok->cur;
+               return STRING;
+       }
+       
        /* Line continuation */
        if (c == '\\') {
                c = tok_nextc(tok);
index 2a1a2b4451b12b293752d84eee40106fb1dde2ac..685a806c74920aa70e744346bbe85ed444b78957 100644 (file)
@@ -481,13 +481,14 @@ parsestr(s)
        char *buf;
        char *p;
        int c;
-       if (*s != '\'') {
+       int quote = *s;
+       if (quote != '\'' && quote != '\"') {
                err_badcall();
                return NULL;
        }
        s++;
        len = strlen(s);
-       if (s[--len] != '\'') {
+       if (s[--len] != quote) {
                err_badcall();
                return NULL;
        }
@@ -505,6 +506,7 @@ parsestr(s)
                /* XXX This assumes ASCII! */
                case '\\': *p++ = '\\'; break;
                case '\'': *p++ = '\''; break;
+               case '\"': *p++ = '\"'; break;
                case 'b': *p++ = '\b'; break;
                case 'f': *p++ = '\014'; break; /* FF */
                case 't': *p++ = '\t'; break;