use crate::err::SJFLError;
use super::{Parse, Variable, Session, match_exact, skip_whitespaces_and_comments};

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Import {
    pub file_name: u32
}

impl Parse for Import {

    fn parse(s: &[u8], mut ind: usize, session: &mut Session) -> Result<(Self, usize), SJFLError> {
        ind = match_exact(s, ind, b"import")?;
        ind = skip_whitespaces_and_comments(s, ind)?;
        let (file_name, end_ind) = Variable::parse(s, ind, session)?;
        ind = skip_whitespaces_and_comments(s, end_ind)?;
        ind = match_exact(s, ind, b";")?;

        Ok((
            Import { file_name: file_name.index },
            ind
        ))
    }

}