summaryrefslogtreecommitdiff
path: root/Parser/pegen.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r--Parser/pegen.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 1bb975d684..66e4b19297 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -371,10 +371,18 @@ tokenizer_error(Parser *p)
errtype = PyExc_IndentationError;
msg = "too many levels of indentation";
break;
- case E_LINECONT:
- col_offset = strlen(strtok(p->tok->buf, "\n")) - 1;
+ case E_LINECONT: {
+ char* loc = strrchr(p->tok->buf, '\n');
+ const char* last_char = p->tok->cur - 1;
+ if (loc != NULL && loc != last_char) {
+ col_offset = p->tok->cur - loc - 1;
+ p->tok->buf = loc;
+ } else {
+ col_offset = last_char - p->tok->buf - 1;
+ }
msg = "unexpected character after line continuation character";
break;
+ }
default:
msg = "unknown parsing error";
}