summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-16 21:06:33 (GMT)
committerGitHub <noreply@github.com>2022-07-16 21:06:33 (GMT)
commit964431eaeb1905a95cb1bd745d0b9c0052db4b94 (patch)
treee1c48b9a5118f2e4324f05355690cd6487c625da /Parser
parent3781d1a45815b5f4455491efd036babc084101b3 (diff)
downloadcpython-964431eaeb1905a95cb1bd745d0b9c0052db4b94.zip
cpython-964431eaeb1905a95cb1bd745d0b9c0052db4b94.tar.gz
cpython-964431eaeb1905a95cb1bd745d0b9c0052db4b94.tar.bz2
gh-94869: Fix the location in some expressions for multi-line f-string ast nodes (GH-94895) (#94911)
(cherry picked from commit 2e9da8e3522764d09f1d6054a2be567e91a30812) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/string_parser.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Parser/string_parser.c b/Parser/string_parser.c
index 80f158b..d33260d 100644
--- a/Parser/string_parser.c
+++ b/Parser/string_parser.c
@@ -315,6 +315,9 @@ fstring_find_expr_location(Token *parent, const char* expr_start, char *expr_str
start--;
}
*p_cols += (int)(expr_start - start);
+ if (*start == '\n') {
+ *p_cols -= 1;
+ }
}
/* adjust the start based on the number of newlines encountered
before the f-string expression */
@@ -400,7 +403,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
NULL, p->arena);
p2->starting_lineno = t->lineno + lines;
- p2->starting_col_offset = t->col_offset + cols;
+ p2->starting_col_offset = lines != 0 ? cols : t->col_offset + cols;
expr = _PyPegen_run_parser(p2);