mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-42918: Improve build-in function compile() in mode 'single' (GH-29934)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
98e506ae8a
commit
28179aac79
3 changed files with 6 additions and 19 deletions
|
|
@ -675,31 +675,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 (;;) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue