From 3e6ab82179f7b9a1df915f4bd0d6e48a454d942c Mon Sep 17 00:00:00 2001 From: Li Weiwei Date: Fri, 18 May 2018 11:15:53 +0800 Subject: [PATCH] py/repl: Fix handling of unmatched brackets and unfinished quotes. Before this patch: >>> print(') ... ') Traceback (most recent call last): File "", line 1 SyntaxError: invalid syntax After this patch: >>> print(') Traceback (most recent call last): File "", line 1 SyntaxError: invalid syntax This matches CPython and prevents getting stuck in REPL continuation when a 1-quote is unmatched. --- py/repl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/py/repl.c b/py/repl.c index 5dce8bbb7d..da0fefb3a9 100644 --- a/py/repl.c +++ b/py/repl.c @@ -106,8 +106,13 @@ bool mp_repl_continue_with_input(const char *input) { } } - // continue if unmatched brackets or quotes - if (n_paren > 0 || n_brack > 0 || n_brace > 0 || in_quote == Q_3_SINGLE || in_quote == Q_3_DOUBLE) { + // continue if unmatched 3-quotes + if (in_quote == Q_3_SINGLE || in_quote == Q_3_DOUBLE) { + return true; + } + + // continue if unmatched brackets, but only if not in a 1-quote + if ((n_paren > 0 || n_brack > 0 || n_brace > 0) && in_quote == Q_NONE) { return true; }