pub fn next_token(&mut self) -> Result<Token, Box<dyn Error>> {
        let mut int_value = 0;
        let mut lexeme = String::new();
        let mut string_table_id = None;
        let token_type = match self.next_char() {
            Some(c) => match c {
                '=' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::EQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::ASSIGN
                        }
                    },
                    None => TokenType::EOF,
                },
                '!' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::NOTEQ,
                        _ => return Err(format!("Unknown operator found: !{}", c).into()),
                    },
                    None => TokenType::EOF,
                },
                '>' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::GTEQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::GT
                        }
                    },
                    None => TokenType::EOF,
                },
                '<' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::LTEQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::LT
                        }
                    },
                    None => TokenType::EOF,
                },
                '+' => TokenType::PLUS,
                '-' => match self.next_char() {
                    Some(c) => match c {
                        '>' => TokenType::ARROW,
                        _ => {
                            self.putback_char(c);
                            TokenType::MINUS
                        }
                    },
                    None => TokenType::EOF,
                },
                '*' => TokenType::STAR,
                '/' => TokenType::SLASH,
                ';' => TokenType::SEMI,
                '(' => TokenType::LPAREN,
                ')' => TokenType::RPAREN,
                '{' => TokenType::LBRACE,
                '}' => TokenType::RBRACE,
                ',' => TokenType::COMMA,
                '&' => TokenType::AMPERSAND,
                '[' => TokenType::LBRACKET,
                ']' => TokenType::RBRACKET,
                '.' => TokenType::DOT,
                ':' => TokenType::COLON,
                '0'..='9' => {
                    int_value = self.scan_int(c) as i32;
                    TokenType::INTLIT
                }
                '\'' => {
                    int_value = self.scan_char()? as i32;
                    TokenType::INTLIT
                }
                '"' => {
                    string_table_id = Some(self.scan_strlit()?);
                    TokenType::STRLIT
                }
                c if c.is_alphabetic() => {
                    lexeme.push_str(&self.scan_ident(c));
                    self.token_type_from_lexeme(&lexeme)
                }
                _ => return Err(format!("Unknown character found: {}", c).into()),
            },
            None => TokenType::EOF,
        };

        Ok(Token {
            token_type,
            int_value,
            lexeme,
            string_table_id,
        })
    }
// Consume current token and scan in the next one
Consume current token and scan in the next one
Consume current token and scan in the next one
pub fn next_token(&mut self) -> Result<Token, Box<dyn Error>> {
        let mut int_value = 0;
        let mut lexeme = String::new();
        let mut string_table_id = None;
        let token_type = match self.next_char() {
            Some(c) => match c {
                '=' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::EQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::ASSIGN
                        }
                    },
                    None => TokenType::EOF,
                },
                '!' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::NOTEQ,
                        _ => return Err(format!("Unknown operator found: !{}", c).into()),
                    },
                    None => TokenType::EOF,
                },
                '>' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::GTEQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::GT
                        }
                    },
                    None => TokenType::EOF,
                },
                '<' => match self.next_char() {
                    Some(c) => match c {
                        '=' => TokenType::LTEQ,
                        _ => {
                            self.putback_char(c);
                            TokenType::LT
                        }
                    },
                    None => TokenType::EOF,
                },
                '+' => TokenType::PLUS,
                '-' => match self.next_char() {
                    Some(c) => match c {
                        '>' => TokenType::ARROW,
                        _ => {
                            self.putback_char(c);
                            TokenType::MINUS
                        }
                    },
                    None => TokenType::EOF,
                },
                '*' => TokenType::STAR,
                '/' => TokenType::SLASH,
                ';' => TokenType::SEMI,
                '(' => TokenType::LPAREN,
                ')' => TokenType::RPAREN,
                '{' => TokenType::LBRACE,
                '}' => TokenType::RBRACE,
                ',' => TokenType::COMMA,
                '&' => TokenType::AMPERSAND,
                '[' => TokenType::LBRACKET,
                ']' => TokenType::RBRACKET,
                '.' => TokenType::DOT,
                ':' => TokenType::COLON,
                '0'..='9' => {
                    int_value = self.scan_int(c) as i32;
                    TokenType::INTLIT
                }
                '\'' => {
                    int_value = self.scan_char()? as i32;
                    TokenType::INTLIT
                }
                '"' => {
                    string_table_id = Some(self.scan_strlit()?);
                    TokenType::STRLIT
                }
                c if c.is_alphabetic() => {
                    lexeme.push_str(&self.scan_ident(c));
                    self.token_type_from_lexeme(&lexeme)
                }
                _ => return Err(format!("Unknown character found: {}", c).into()),
            },
            None => TokenType::EOF,
        };
        Ok(Token {
            token_type,
            int_value,
            lexeme,
            string_table_id,
        })
    }
pub fn next_token ( & mut self ) -> Result < Token , Box < dyn Error > > { let mut int_value = 0 ; let mut lexeme = String :: new ( ) ; let mut string_table_id = None ; let token_type = match self . next_char ( ) { Some ( c ) => match c { '=' => match self . next_char ( ) { Some ( c ) => match c { '=' => TokenType :: EQ , _ => { self . putback_char ( c ) ; TokenType :: ASSIGN } } , None => TokenType :: EOF , } , '!' => match self . next_char ( ) { Some ( c ) => match c { '=' => TokenType :: NOTEQ , _ => return Err ( format ! ( " " c ) . into ( ) ) , } , None => TokenType :: EOF , } , '>' => match self . next_char ( ) { Some ( c ) => match c { '=' => TokenType :: GTEQ , _ => { self . putback_char ( c ) ; TokenType :: GT } } , None => TokenType :: EOF , } , '<' => match self . next_char ( ) { Some ( c ) => match c { '=' => TokenType :: LTEQ , _ => { self . putback_char ( c ) ; TokenType :: LT } } , None => TokenType :: EOF , } , '+' => TokenType :: PLUS , '-' => match self . next_char ( ) { Some ( c ) => match c { '>' => TokenType :: ARROW , _ => { self . putback_char ( c ) ; TokenType :: MINUS } } , None => TokenType :: EOF , } , '*' => TokenType :: STAR , '/' => TokenType :: SLASH , ';' => TokenType :: SEMI , '(' => TokenType :: LPAREN , ')' => TokenType :: RPAREN , '{' => TokenType :: LBRACE , '}' => TokenType :: RBRACE , ',' => TokenType :: COMMA , '&' => TokenType :: AMPERSAND , '[' => TokenType :: LBRACKET , ']' => TokenType :: RBRACKET , '.' => TokenType :: DOT , ':' => TokenType :: COLON , '0' ..= '9' => { int_value = self . scan_int ( c ) as i32 ; TokenType :: INTLIT } '\'' => { int_value = self . scan_char ( ) ? as i32 ; TokenType :: INTLIT } '"' => { string_table_id = Some ( self . scan_strlit ( ) ? ) ; TokenType :: STRLIT } c if c . is_alphabetic ( ) => { lexeme . push_str ( & self . scan_ident ( c ) ) ; self . token_type_from_lexeme ( & lexeme ) } _ => return Err ( format ! ( " " c ) . into ( ) ) , } , None => TokenType :: EOF , } ; Ok ( Token { token_type , int_value , lexeme , string_table_id , } ) }
Consume current token and scan in the next one
Consume current token and scan in the next one
&mut self