pub fn next_token(&mut self) -> Result<Token, Error> {
      self.skip_whitespace();
      self.token_start = self.location;

      match self.get() {
         '0'..='9' => {
            let number = self.number()?;
            Ok(self.token(TokenKind::Number(number)))
         }
         '"' => {
            let string = self.string(false)?;
            Ok(self.token(TokenKind::String(Rc::from(string))))
         }
         '\\' => Ok(self.extended_literal()?),

         c if Self::is_identifier_start_char(c) => {
            let identifier = self.identifier();
            Ok(if let Some(keyword) = Self::keyword(identifier) {
               self.token(keyword)
            } else {
               let identifier = Rc::from(identifier);
               self.token(TokenKind::Identifier(identifier))
            })
         }

         '+' => Ok(self.single_char_token(TokenKind::Plus)),
         '-' => Ok(self.single_char_token(TokenKind::Minus)),
         '*' => Ok(self.single_char_token(TokenKind::Star)),
         '/' => Ok(self.single_char_token(TokenKind::Slash)),

         '=' => Ok(self.single_or_double_char_token(TokenKind::Assign, '=', TokenKind::Equal)),
         '!' => Ok(self.single_or_double_char_token(TokenKind::Bang, '=', TokenKind::NotEqual)),
         '<' => Ok(self.single_or_double_char_token(TokenKind::Less, '=', TokenKind::LessEqual)),
         '>' => {
            Ok(self.single_or_double_char_token(TokenKind::Greater, '=', TokenKind::GreaterEqual))
         }

         '.' => Ok(self.single_char_token(TokenKind::Dot)),
         '@' => Ok(self.single_char_token(TokenKind::At)),

         '(' => Ok(self.single_char_token(TokenKind::LeftParen)),
         ')' => Ok(self.single_char_token(TokenKind::RightParen)),
         '[' => Ok(self.single_char_token(TokenKind::LeftBracket)),
         ']' => Ok(self.single_char_token(TokenKind::RightBracket)),
         ',' => Ok(self.single_char_token(TokenKind::Comma)),
         Self::EOF => Ok(self.token(TokenKind::Eof)),
         other => Err(self.error(ErrorKind::InvalidCharacter(other))),
      }
   }
/// Parses the next token and returns it.
Parses the next token and returns it.
Parses the next token and returns it .
pub fn next_token(&mut self) -> Result<Token, Error> {
      self.skip_whitespace();
      self.token_start = self.location;
      match self.get() {
         '0'..='9' => {
            let number = self.number()?;
            Ok(self.token(TokenKind::Number(number)))
         }
         '"' => {
            let string = self.string(false)?;
            Ok(self.token(TokenKind::String(Rc::from(string))))
         }
         '\\' => Ok(self.extended_literal()?),
         c if Self::is_identifier_start_char(c) => {
            let identifier = self.identifier();
            Ok(if let Some(keyword) = Self::keyword(identifier) {
               self.token(keyword)
            } else {
               let identifier = Rc::from(identifier);
               self.token(TokenKind::Identifier(identifier))
            })
         }
         '+' => Ok(self.single_char_token(TokenKind::Plus)),
         '-' => Ok(self.single_char_token(TokenKind::Minus)),
         '*' => Ok(self.single_char_token(TokenKind::Star)),
         '/' => Ok(self.single_char_token(TokenKind::Slash)),
         '=' => Ok(self.single_or_double_char_token(TokenKind::Assign, '=', TokenKind::Equal)),
         '!' => Ok(self.single_or_double_char_token(TokenKind::Bang, '=', TokenKind::NotEqual)),
         '<' => Ok(self.single_or_double_char_token(TokenKind::Less, '=', TokenKind::LessEqual)),
         '>' => {
            Ok(self.single_or_double_char_token(TokenKind::Greater, '=', TokenKind::GreaterEqual))
         }
         '.' => Ok(self.single_char_token(TokenKind::Dot)),
         '@' => Ok(self.single_char_token(TokenKind::At)),
         '(' => Ok(self.single_char_token(TokenKind::LeftParen)),
         ')' => Ok(self.single_char_token(TokenKind::RightParen)),
         '[' => Ok(self.single_char_token(TokenKind::LeftBracket)),
         ']' => Ok(self.single_char_token(TokenKind::RightBracket)),
         ',' => Ok(self.single_char_token(TokenKind::Comma)),
         Self::EOF => Ok(self.token(TokenKind::Eof)),
         other => Err(self.error(ErrorKind::InvalidCharacter(other))),
      }
   }
pub fn next_token ( & mut self ) -> Result < Token , Error > { self . skip_whitespace ( ) ; self . token_start = self . location ; match self . get ( ) { '0' ..= '9' => { let number = self . number ( ) ? ; Ok ( self . token ( TokenKind :: Number ( number ) ) ) } '"' => { let string = self . string ( false ) ? ; Ok ( self . token ( TokenKind :: String ( Rc :: from ( string ) ) ) ) } '\\' => Ok ( self . extended_literal ( ) ? ) , c if Self :: is_identifier_start_char ( c ) => { let identifier = self . identifier ( ) ; Ok ( if let Some ( keyword ) = Self :: keyword ( identifier ) { self . token ( keyword ) } else { let identifier = Rc :: from ( identifier ) ; self . token ( TokenKind :: Identifier ( identifier ) ) } ) } '+' => Ok ( self . single_char_token ( TokenKind :: Plus ) ) , '-' => Ok ( self . single_char_token ( TokenKind :: Minus ) ) , '*' => Ok ( self . single_char_token ( TokenKind :: Star ) ) , '/' => Ok ( self . single_char_token ( TokenKind :: Slash ) ) , '=' => Ok ( self . single_or_double_char_token ( TokenKind :: Assign , '=' , TokenKind :: Equal ) ) , '!' => Ok ( self . single_or_double_char_token ( TokenKind :: Bang , '=' , TokenKind :: NotEqual ) ) , '<' => Ok ( self . single_or_double_char_token ( TokenKind :: Less , '=' , TokenKind :: LessEqual ) ) , '>' => { Ok ( self . single_or_double_char_token ( TokenKind :: Greater , '=' , TokenKind :: GreaterEqual ) ) } '.' => Ok ( self . single_char_token ( TokenKind :: Dot ) ) , '@' => Ok ( self . single_char_token ( TokenKind :: At ) ) , '(' => Ok ( self . single_char_token ( TokenKind :: LeftParen ) ) , ')' => Ok ( self . single_char_token ( TokenKind :: RightParen ) ) , '[' => Ok ( self . single_char_token ( TokenKind :: LeftBracket ) ) , ']' => Ok ( self . single_char_token ( TokenKind :: RightBracket ) ) , ',' => Ok ( self . single_char_token ( TokenKind :: Comma ) ) , Self :: EOF => Ok ( self . token ( TokenKind :: Eof ) ) , other => Err ( self . error ( ErrorKind :: InvalidCharacter ( other ) ) ) , } }
Parses the next token and returns it.
Parses the next token and returns it .
&mut self