Remove duplication in lexer for string endings