Alllow input transformers to raise SyntaxError

This is a rebase and continuation of @vbraun's PR #4089, which allows input transformers to raise a SyntaxError if they consider a line of input code invalid.

I've made a few fixes from #4089, refactored `run_cell` a bit, and turned the test for the terminal interact loop into an in-process test using some generator magic.