modularize lexer implementation