Fix handling of comments at end of input

Fixes #382.