Some operators are two characters that start with a one-character operator - == begins like =, != begins like !. Today you teach the lexer to peek at the next character to tell them apart.
Lex the two-character operators == and != distinctly from the single-character = and !.
Now that a single character no longer always determines the token, the lexer
needs to look ahead. When it sees =, the token is ASSIGN only if the
next character is not another =; if it is, the two together are the equality
operator EQ. The same choice separates ! (BANG) from != (NOT_EQ).
The tool is a peekChar that returns the next character without advancing. Peek,
decide, and only consume the second character when it is really part of a
two-character operator. This look-ahead-by-one is the same trick every lexer uses
for multi-character operators, and it keeps ! usable on its own as the “not”
operator you will need soon.
case '=':if l.peekChar() == '=' { // look ahead without consumingl.readChar()return Token{EQ, "=="}}return Token{ASSIGN, "="}// peekChar returns the next char but does not advance