use crate::{Statement, Session, SJFLError};
use crate::parse::{Parse, match_exact};
use crate::err::Span;
use super::{Assignment, Import};

impl Parse for Statement {

    fn parse(s: &[u8], ind: usize, session: &mut Session) -> Result<(Self, usize), SJFLError> {

        if let Ok(new_ind) = match_exact(s, ind, b";") {
            Ok((Statement::NOP, new_ind))
        }

        else if let Ok((import, new_ind)) = Import::parse(s, ind, session) {
            Ok((Statement::Import(import), new_ind))
        }

        else if let Ok((assignment, new_ind)) = Assignment::parse(s, ind, session) {
            Ok((Statement::Assignment(assignment), new_ind))
        }

        else {
            Err(SJFLError::UnexpectedChar(s[ind], Span::from_index(ind)))
        }

    }

}