#define ISTERMINAL(x) ((x) < NT_OFFSET)
#define ISNONTERMINAL(x) ((x) >= NT_OFFSET)
#define ISEOF(x) ((x) == ENDMARKER)
+#define ISWHITESPACE(x) ((x) == ENDMARKER || \
+ (x) == NEWLINE || \
+ (x) == INDENT || \
+ (x) == DEDENT)
PyAPI_DATA(const char * const) _PyParser_TokenNames[]; /* Token names */
# lambda doesn't work without parens, because the colon
# makes the parser think it's a format_spec
- self.assertAllRaise(SyntaxError, 'unexpected EOF while parsing',
+ self.assertAllRaise(SyntaxError, 'invalid syntax',
["f'{lambda x:x}'",
])
--- /dev/null
+Fix the tokenizer to display the correct error message, when there is a SyntaxError on the last input character and no newline follows. It used to be `unexpected EOF while parsing`, while it should be `invalid syntax`.
\ No newline at end of file
PyParser_AddToken(ps, (int)type, str,
lineno, col_offset, tok->lineno, end_col_offset,
&(err_ret->expected))) != E_OK) {
+ if (tok->done == E_EOF && !ISWHITESPACE(type)) {
+ tok->done = E_SYNTAX;
+ }
if (err_ret->error != E_DONE) {
PyObject_FREE(str);
err_ret->token = type;
#define ISTERMINAL(x) ((x) < NT_OFFSET)
#define ISNONTERMINAL(x) ((x) >= NT_OFFSET)
#define ISEOF(x) ((x) == ENDMARKER)
+#define ISWHITESPACE(x) ((x) == ENDMARKER || \\
+ (x) == NEWLINE || \\
+ (x) == INDENT || \\
+ (x) == DEDENT)
PyAPI_DATA(const char * const) _PyParser_TokenNames[]; /* Token names */