lexer.py: rewrite lexer