Catch SyntaxError from tokenizing for traceback

I don't think there's an easy way to test this, but I've verified the
fix by hand.

Closes gh-6300
Merge pull request #6301 from takluyver/i6300

Catch SyntaxError from tokenizing for traceback