lib/ripl/rc/multiline.rb in ripl-rc-0.1.4 vs lib/ripl/rc/multiline.rb in ripl-rc-0.1.5

- old
+ new

@@ -2,20 +2,20 @@ require 'ripl' # from https://github.com/janlelis/ripl-multi_line module Ripl::Rc; end module Ripl::Rc::Multiline - ERROR_REGEXP = /#{ - [ %q%unexpected \$end%, - %q%unterminated [a-z]+ meets end of file%, + ERROR_REGEXP = Regexp.new( + [ "unexpected \\$end", + "unterminated [a-z]+ meets end of file", # rubinius - %q%expecting '\\n' or ';'%, - %q%missing 'end'%, - %q%expecting '}'%, + "expecting '\\\\n' or ';'", + "missing 'end'", + "expecting '}'", # jruby - %q%syntax error, unexpected end-of-file%, - ]*'|' }/ + "syntax error, unexpected end-of-file", + ].join('|')) def before_loop @rc_multiline_buffer = [] super end @@ -35,21 +35,25 @@ end end def print_eval_error(e) if e.is_a?(SyntaxError) && e.message =~ ERROR_REGEXP - @rc_multiline_buffer << @input + @rc_multiline_buffer << @input if @rc_multiline_buffer.empty? + history.pop throw :rc_multiline_cont else super end end def loop_eval(input) if @rc_multiline_buffer.empty? super else - super "#{@rc_multiline_buffer.join("\n")}\n#{input}" + @rc_multiline_buffer << input + history.pop + history << "\n" + (str = @rc_multiline_buffer.join("\n")) + super str end end def handle_interrupt if @rc_multiline_buffer.empty?