Make pasting to the REPL more robust to syntax errors

All text including and following a syntax error is output together on one line.

This follows #6683, and together with d1095bb158 I think pasting should be *much* less buggy (and still retain the incremental execution of multiple statements).

cc: @loladiro