pub fn next_token(&mut self) -> LexResult<WithSpan<Token>> {
        self.skip_whitespace();

        let initial_position = self.current_position;

        let token = if let Some(c) = self.read_char() {
            match c {
                '+' => Token::Plus,
                '-' => Token::Minus,
                '*' => match self.peek_char() {
                    // Double star
                    Some('*') => {
                        self.read_char();
                        Token::StarStar
                    }
                    _ => Token::Star,
                },
                '/' => Token::Slash,

                '=' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::EqualEqual
                    }
                    _ => Token::Equal,
                },
                '!' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::BangEqual
                    }
                    _ => Token::Bang,
                },
                '<' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::LessEqual
                    }
                    _ => Token::LessThan,
                },
                '>' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::GreaterEqual
                    }
                    _ => Token::GreaterThan,
                },

                ',' => Token::Comma,
                '.' => Token::Dot,
                ';' => Token::Semicolon,
                ':' => Token::Colon,

                '(' => Token::LeftParen,
                ')' => Token::RightParen,
                '{' => Token::LeftBrace,
                '}' => Token::RightBrace,
                '[' => Token::LeftBracket,
                ']' => Token::RightBracket,

                '&' => match self.peek_char() {
                    // AndAnd: &&
                    Some('&') => {
                        self.read_char();
                        Token::AndAnd
                    }
                    _ => return Err(LexError::UnexpectedToken(c)),
                },
                '|' => match self.peek_char() {
                    // OrOr: ||
                    Some('|') => {
                        self.read_char();
                        Token::OrOr
                    }
                    _ => return Err(LexError::UnexpectedToken(c)),
                },

                '"' | '\'' => self.read_string(c)?,

                c if is_digit(c) => self.read_number(c)?,
                c if is_identifier_char(c) => self.read_identifier_or_keyword(c)?,

                _ => return Err(LexError::UnexpectedToken(c)),
            }
        } else {
            Token::Eof
        };

        let span = Span::new(initial_position, self.current_position);

        Ok(WithSpan::new(token, span))
    }
/// Read a new token from the characters list.
Read a new token from the characters list.
Read a new token from the characters list .
pub fn next_token(&mut self) -> LexResult<WithSpan<Token>> {
        self.skip_whitespace();
        let initial_position = self.current_position;
        let token = if let Some(c) = self.read_char() {
            match c {
                '+' => Token::Plus,
                '-' => Token::Minus,
                '*' => match self.peek_char() {
                    // Double star
                    Some('*') => {
                        self.read_char();
                        Token::StarStar
                    }
                    _ => Token::Star,
                },
                '/' => Token::Slash,
                '=' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::EqualEqual
                    }
                    _ => Token::Equal,
                },
                '!' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::BangEqual
                    }
                    _ => Token::Bang,
                },
                '<' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::LessEqual
                    }
                    _ => Token::LessThan,
                },
                '>' => match self.peek_char() {
                    // Double equal
                    Some('=') => {
                        self.read_char();
                        Token::GreaterEqual
                    }
                    _ => Token::GreaterThan,
                },
                ',' => Token::Comma,
                '.' => Token::Dot,
                ';' => Token::Semicolon,
                ':' => Token::Colon,
                '(' => Token::LeftParen,
                ')' => Token::RightParen,
                '{' => Token::LeftBrace,
                '}' => Token::RightBrace,
                '[' => Token::LeftBracket,
                ']' => Token::RightBracket,
                '&' => match self.peek_char() {
                    // AndAnd: &&
                    Some('&') => {
                        self.read_char();
                        Token::AndAnd
                    }
                    _ => return Err(LexError::UnexpectedToken(c)),
                },
                '|' => match self.peek_char() {
                    // OrOr: ||
                    Some('|') => {
                        self.read_char();
                        Token::OrOr
                    }
                    _ => return Err(LexError::UnexpectedToken(c)),
                },
                '"' | '\'' => self.read_string(c)?,
                c if is_digit(c) => self.read_number(c)?,
                c if is_identifier_char(c) => self.read_identifier_or_keyword(c)?,
                _ => return Err(LexError::UnexpectedToken(c)),
            }
        } else {
            Token::Eof
        };
        let span = Span::new(initial_position, self.current_position);
        Ok(WithSpan::new(token, span))
    }
pub fn next_token ( & mut self ) -> LexResult < WithSpan < Token > > { self . skip_whitespace ( ) ; let initial_position = self . current_position ; let token = if let Some ( c ) = self . read_char ( ) { match c { '+' => Token :: Plus , '-' => Token :: Minus , '*' => match self . peek_char ( ) { // Double star Some ( '*' ) => { self . read_char ( ) ; Token :: StarStar } _ => Token :: Star , } , '/' => Token :: Slash , '=' => match self . peek_char ( ) { // Double equal Some ( '=' ) => { self . read_char ( ) ; Token :: EqualEqual } _ => Token :: Equal , } , '!' => match self . peek_char ( ) { // Double equal Some ( '=' ) => { self . read_char ( ) ; Token :: BangEqual } _ => Token :: Bang , } , '<' => match self . peek_char ( ) { // Double equal Some ( '=' ) => { self . read_char ( ) ; Token :: LessEqual } _ => Token :: LessThan , } , '>' => match self . peek_char ( ) { // Double equal Some ( '=' ) => { self . read_char ( ) ; Token :: GreaterEqual } _ => Token :: GreaterThan , } , ',' => Token :: Comma , '.' => Token :: Dot , ';' => Token :: Semicolon , ':' => Token :: Colon , '(' => Token :: LeftParen , ')' => Token :: RightParen , '{' => Token :: LeftBrace , '}' => Token :: RightBrace , '[' => Token :: LeftBracket , ']' => Token :: RightBracket , '&' => match self . peek_char ( ) { // AndAnd: && Some ( '&' ) => { self . read_char ( ) ; Token :: AndAnd } _ => return Err ( LexError :: UnexpectedToken ( c ) ) , } , '|' => match self . peek_char ( ) { // OrOr: || Some ( '|' ) => { self . read_char ( ) ; Token :: OrOr } _ => return Err ( LexError :: UnexpectedToken ( c ) ) , } , '"' | '\'' => self . read_string ( c ) ? , c if is_digit ( c ) => self . read_number ( c ) ? , c if is_identifier_char ( c ) => self . read_identifier_or_keyword ( c ) ? , _ => return Err ( LexError :: UnexpectedToken ( c ) ) , } } else { Token :: Eof } ; let span = Span :: new ( initial_position , self . current_position ) ; Ok ( WithSpan :: new ( token , span ) ) }
Read a new token from the characters list.
Read a new token from the characters list .
&mut self