mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-2180: Treat line continuation at EOF as a SyntaxError (GH-13401)
This makes the parser consistent with the tokenize module (already the case
in `pypy`).
sample
------
```python
x = 5\
```
before
------
```console
$ python3 t.py
$ python3 -mtokenize t.py
t.py:2:0: error: EOF in multi-line statement
```
after
-----
```console
$ ./python t.py
File "t.py", line 3
x = 5\
^
SyntaxError: unexpected EOF while parsing
$ ./python -m tokenize t.py
t.py:2:0: error: EOF in multi-line statement
```
https://bugs.python.org/issue2180
This commit is contained in:
parent
e917f2ed9a
commit
abea73bf4a
3 changed files with 36 additions and 2 deletions
|
|
@ -983,7 +983,8 @@ tok_nextc(struct tok_state *tok)
|
|||
return EOF;
|
||||
/* Last line does not end in \n,
|
||||
fake one */
|
||||
strcpy(tok->inp, "\n");
|
||||
if (tok->inp[-1] != '\n')
|
||||
strcpy(tok->inp, "\n");
|
||||
}
|
||||
tok->inp = strchr(tok->inp, '\0');
|
||||
done = tok->inp[-1] == '\n';
|
||||
|
|
@ -1674,6 +1675,14 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
|
|||
tok->cur = tok->inp;
|
||||
return ERRORTOKEN;
|
||||
}
|
||||
c = tok_nextc(tok);
|
||||
if (c == EOF) {
|
||||
tok->done = E_EOF;
|
||||
tok->cur = tok->inp;
|
||||
return ERRORTOKEN;
|
||||
} else {
|
||||
tok_backup(tok, c);
|
||||
}
|
||||
tok->cont_line = 1;
|
||||
goto again; /* Read next line */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue