Skip to content
Snippets Groups Projects
Commit 3e6ab821 authored by Li Weiwei's avatar Li Weiwei Committed by Damien George
Browse files

py/repl: Fix handling of unmatched brackets and unfinished quotes.

Before this patch:

    >>> print(')
    ... ')
    Traceback (most recent call last):
      File "<stdin>", line 1
    SyntaxError: invalid syntax

After this patch:

    >>> print(')
    Traceback (most recent call last):
      File "<stdin>", line 1
    SyntaxError: invalid syntax

This matches CPython and prevents getting stuck in REPL continuation when a
1-quote is unmatched.
parent 869024dd
No related branches found
No related tags found
No related merge requests found
...@@ -106,8 +106,13 @@ bool mp_repl_continue_with_input(const char *input) { ...@@ -106,8 +106,13 @@ bool mp_repl_continue_with_input(const char *input) {
} }
} }
// continue if unmatched brackets or quotes // continue if unmatched 3-quotes
if (n_paren > 0 || n_brack > 0 || n_brace > 0 || in_quote == Q_3_SINGLE || in_quote == Q_3_DOUBLE) { 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; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment