[lexer] Refactoring of scanning functions