gh-94869: Fix the location in some expressions for multi-line f-string ast nodes (GH-94895)

(cherry picked from commit 2e9da8e352)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-07-16 12:16:51 -07:00 committed by GitHub
parent 8c08e86d8d
commit e121cb5814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View file

@ -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);