diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-07-16 18:51:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-16 18:51:53 (GMT) |
commit | 2e9da8e3522764d09f1d6054a2be567e91a30812 (patch) | |
tree | aa60441243440f872f00f86daa4302fad189891e /Parser/string_parser.c | |
parent | 4b4439daed3992a5c5a83b86596d6e00ac3c1203 (diff) | |
download | cpython-2e9da8e3522764d09f1d6054a2be567e91a30812.zip cpython-2e9da8e3522764d09f1d6054a2be567e91a30812.tar.gz cpython-2e9da8e3522764d09f1d6054a2be567e91a30812.tar.bz2 |
gh-94869: Fix the location in some expressions for multi-line f-string ast nodes (#94895)
Diffstat (limited to 'Parser/string_parser.c')
-rw-r--r-- | Parser/string_parser.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Parser/string_parser.c b/Parser/string_parser.c index 984c05d..9bc3b08 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -326,6 +326,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 */ @@ -416,7 +419,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); |