pub fn parse_program(&mut self) -> Result<Program, Vec<ParseError>> {
        let mut program = Program::new();
        let mut errors: Vec<ParseError> = Vec::new();

        // Prepare parser by fetching first two tokens
        match self.lexer.next_token() {
            Ok(tok) => self.current_token = tok,
            Err(err) => return Err(vec![ParseError::SyntaxError(err)]),
        };
        match self.lexer.next_token() {
            Ok(tok) => self.peek_token = tok,
            Err(err) => return Err(vec![ParseError::SyntaxError(err)]),
        };

        // Loop through tokens, parsing statements until EOF
        while self.current_token.value != Token::Eof {
            match self.parse_statement() {
                Ok(statement) => program.statements.push(statement),
                // Encountering a SyntaxError should exit out immediately
                Err(ParseError::SyntaxError(err)) => return Err(vec![err.into()]),
                Err(error) => errors.push(error),
            }

            // Consume the next token
            self.next_token()
                // exit out if there was a LexError
                .map_err(|err| vec![err])?;
        }

        if errors.is_empty() == false {
            return Err(errors);
        }

        Ok(program)
    }
/// Parse the entire input as a program.
Parse the entire input as a program.
Parse the entire input as a program .
pub fn parse_program(&mut self) -> Result<Program, Vec<ParseError>> {
        let mut program = Program::new();
        let mut errors: Vec<ParseError> = Vec::new();
        // Prepare parser by fetching first two tokens
        match self.lexer.next_token() {
            Ok(tok) => self.current_token = tok,
            Err(err) => return Err(vec![ParseError::SyntaxError(err)]),
        };
        match self.lexer.next_token() {
            Ok(tok) => self.peek_token = tok,
            Err(err) => return Err(vec![ParseError::SyntaxError(err)]),
        };
        // Loop through tokens, parsing statements until EOF
        while self.current_token.value != Token::Eof {
            match self.parse_statement() {
                Ok(statement) => program.statements.push(statement),
                // Encountering a SyntaxError should exit out immediately
                Err(ParseError::SyntaxError(err)) => return Err(vec![err.into()]),
                Err(error) => errors.push(error),
            }
            // Consume the next token
            self.next_token()
                // exit out if there was a LexError
                .map_err(|err| vec![err])?;
        }
        if errors.is_empty() == false {
            return Err(errors);
        }
        Ok(program)
    }
pub fn parse_program ( & mut self ) -> Result < Program , Vec < ParseError > > { let mut program = Program :: new ( ) ; let mut errors : Vec < ParseError > = Vec :: new ( ) ; // Prepare parser by fetching first two tokens match self . lexer . next_token ( ) { Ok ( tok ) => self . current_token = tok , Err ( err ) => return Err ( vec ! [ ParseError SyntaxError ( err ) ] ) , } ; match self . lexer . next_token ( ) { Ok ( tok ) => self . peek_token = tok , Err ( err ) => return Err ( vec ! [ ParseError SyntaxError ( err ) ] ) , } ; // Loop through tokens, parsing statements until EOF while self . current_token . value != Token :: Eof { match self . parse_statement ( ) { Ok ( statement ) => program . statements . push ( statement ) , // Encountering a SyntaxError should exit out immediately Err ( ParseError :: SyntaxError ( err ) ) => return Err ( vec ! [ err into ( ) ] ) , Err ( error ) => errors . push ( error ) , } // Consume the next token self . next_token ( ) // exit out if there was a LexError . map_err ( | err | vec ! [ err ] ) ? ; } if errors . is_empty ( ) == false { return Err ( errors ) ; } Ok ( program ) }
Parse the entire input as a program.
Parse the entire input as a program .
&mut self