diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index 3e5129be6..99e5b257a 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -220,7 +220,7 @@ def input_reline(*args) Pry::InputLock.for(:all).interruptible_region do input.readmultiline(*args) do |multiline_input| Pry.commands.find_command(multiline_input) || - (Prism.parse_success?(multiline_input) && !Reline::IOGate.in_pasting?) + (complete_expression?(multiline_input) && !Reline::IOGate.in_pasting?) end end end @@ -264,6 +264,17 @@ def set_readline_output @readline_output = (Readline.output = Pry.config.output) if piping? end + UNEXPECTED_TOKENS = %i[unexpected_token_ignore lambda_open].freeze + + def complete_expression?(multiline_input) + lex = Prism.lex(multiline_input) + + errors = lex.errors + return true if errors.empty? + + errors.any? { |error| UNEXPECTED_TOKENS.include?(error.type) } + end + # Calculates correct overhang for current line. Supports vi Readline # mode and its indicators such as "(ins)" or "(cmd)". #