From 8054fad890bbb6668cb2eb2fb3118222bada5975 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 26 Oct 1993 15:19:44 +0000 Subject: Changes to accept double-quoted strings on input. --- Parser/tokenizer.c | 28 +++++++++++++++++++++++++++- Python/compile.c | 6 ++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 725a2f1..6504e0c 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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); diff --git a/Python/compile.c b/Python/compile.c index 2a1a2b4..685a806 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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; -- cgit v0.12