public SyntaxToken Lex() { _start = _position; _kind = SyntaxKind.BadToken; _value = null; switch (Current) { case '\0': _kind = SyntaxKind.EndOfFileToken; break; case '+': _kind = SyntaxKind.PlusToken; _position++; break; case '-': _kind = SyntaxKind.MinusToken; _position++; break; case '*': _kind = SyntaxKind.StarToken; _position++; break; case '/': _kind = SyntaxKind.SlashToken; _position++; break; case '(': _kind = SyntaxKind.OpenParenthesisToken; _position++; break; case ')': _kind = SyntaxKind.CloseParenthesisToken; _position++; break; case '{': _kind = SyntaxKind.OpenBraceToken; _position++; break; case '}': _kind = SyntaxKind.CloseBraceToken; _position++; break; case ':': _kind = SyntaxKind.ColonToken; _position++; break; case ',': _kind = SyntaxKind.CommaToken; _position++; break; case '~': _kind = SyntaxKind.TildeToken; _position++; break; case '^': _kind = SyntaxKind.HatToken; _position++; break; case '&': _position++; if (Current != '&') { _kind = SyntaxKind.AmpersandToken; } else { _kind = SyntaxKind.AmpersandAmpersandToken; _position++; } break; case '|': _position++; if (Current != '|') { _kind = SyntaxKind.PipeToken; } else { _kind = SyntaxKind.PipePipeToken; _position++; } break; case '=': _position++; if (Current != '=') { _kind = SyntaxKind.EqualsToken; } else { _kind = SyntaxKind.EqualsEqualsToken; _position++; } break; case '!': _position++; if (Current != '=') { _kind = SyntaxKind.BangToken; } else { _kind = SyntaxKind.BangEqualsToken; _position++; } break; case '<': _position++; if (Current != '=') { _kind = SyntaxKind.LessToken; } else { _kind = SyntaxKind.LessOrEqualsToken; _position++; } break; case '>': _position++; if (Current != '=') { _kind = SyntaxKind.GreaterToken; } else { _kind = SyntaxKind.GreaterOrEqualsToken; _position++; } break; case '"': ReadString(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ReadNumber(); break; case ' ': case '\t': case '\n': case '\r': ReadWhiteSpace(); break; default: if (char.IsLetter(Current)) { ReadIdentifierOrKeyword(); } else if (char.IsWhiteSpace(Current)) { ReadWhiteSpace(); } else { _diagnostics.ReportBadCharacter(_position, Current); _position++; } break; } var length = _position - _start; var text = SyntaxFacts.GetText(_kind); if (text == null) { text = _text.ToString(_start, length); } return(new SyntaxToken(_kind, _start, text, _value)); }