-
- Notifications
You must be signed in to change notification settings - Fork 33.5k
bpo-16806: Fix lineno and col_offset for multi-line string tokens. #10021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix ``lineno`` and ``col_offset`` for multi-line string tokens. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -4282,9 +4282,13 @@ fstring_fix_node_location(const node *parent, node *n, char *expr_str) | |
| start--; | ||
| } | ||
| cols += (int)(substr - start); | ||
| /* Fix lineno in mulitline strings. */ | ||
| while ((substr = strchr(substr + 1, '\n'))) | ||
| lines--; | ||
| /* adjust the start based on the number of newlines encountered | ||
| before the f-string expression */ | ||
| for (char* p = parent->n_str; p < substr; p++) { | ||
| if (*p == '\n') { | ||
| lines++; | ||
| } | ||
| } | ||
| ||
| } | ||
| } | ||
| fstring_shift_node_locations(n, lines, cols); | ||
| | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this was incorrect before (being adjusted by
-1due to the multiline string).For instance, here's the ast dump of (using astpretty)
You'll notice that the
BinOpand itsleft(Num) have the samecol_offset