ram_machine/
error.rs

1use crate::parser::CodeParseError;
2
3#[derive(Debug)]
4pub struct ParserErrorChain(Vec<(u32, CodeParseError)>);
5
6impl ParserErrorChain {
7    pub fn new() -> Self {
8        Self(Vec::new())
9    }
10
11    pub fn add(&mut self, (line, err): (u32, CodeParseError)) {
12        self.0.push((line, err))
13    }
14
15    pub fn is_empty(&self) -> bool {
16        self.0.is_empty()
17    }
18}
19
20impl std::fmt::Display for ParserErrorChain {
21    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
22        let mut output: String = "".to_string();
23        for (line, err) in &self.0 {
24            output.push_str(&format!("At line {} found error: {}\n", line, err));
25        }
26        write!(f, "{}", output)
27    }
28}