summaryrefslogtreecommitdiffstats
path: root/Parser/pegen.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-12-27 16:15:44 (GMT)
committerGitHub <noreply@github.com>2021-12-27 16:15:44 (GMT)
commit576e38f9db61ca09ca6dc57ad13b02a7bf9d370a (patch)
tree6112f975dc389f687c223a6a0efb19a540519cae /Parser/pegen.c
parentbb0b5c12419b8fa657c96185d62212aea975f500 (diff)
downloadcpython-576e38f9db61ca09ca6dc57ad13b02a7bf9d370a.zip
cpython-576e38f9db61ca09ca6dc57ad13b02a7bf9d370a.tar.gz
cpython-576e38f9db61ca09ca6dc57ad13b02a7bf9d370a.tar.bz2
bpo-42918: Improve built-in function compile() in mode 'single' (GH-29934) (GH-30040)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> (cherry picked from commit 28179aac796ed1debdce336c4b8ca18e8475d40d) Co-authored-by: Weipeng Hong <hongweichen8888@sina.com>
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r--Parser/pegen.c20
1 files changed, 1 insertions, 19 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index bae073c..0504906 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1131,31 +1131,13 @@ _PyPegen_number_token(Parser *p)
t->end_col_offset, p->arena);
}
-static int // bool
-newline_in_string(Parser *p, const char *cur)
-{
- for (const char *c = cur; c >= p->tok->buf; c--) {
- if (*c == '\'' || *c == '"') {
- return 1;
- }
- }
- return 0;
-}
-
/* Check that the source for a single input statement really is a single
statement by looking at what is left in the buffer after parsing.
Trailing whitespace and comments are OK. */
static int // bool
bad_single_statement(Parser *p)
{
- const char *cur = strchr(p->tok->buf, '\n');
-
- /* Newlines are allowed if preceded by a line continuation character
- or if they appear inside a string. */
- if (!cur || (cur != p->tok->buf && *(cur - 1) == '\\')
- || newline_in_string(p, cur)) {
- return 0;
- }
+ char *cur = p->tok->cur;
char c = *cur;
for (;;) {