Make the lexer into an iterator
Fix type parameters; update tests