Improve %filter/%endfiler error handling

- Barf on forgotten %endfilter directives
- Correctly check for unterminated filter command.
- Show line numbers of the relevant lines.