Improvements to lex.py and tests.