Fix a bug in the lexer and introduce some tests

The lexer still has a bug or two, as some of the tests fail.