shm_rs/dynamic_scheme/
error.rs1use std::fmt;
2use std::sync::Arc;
3
4use crate::{lexer::lexer_error::LexerError, LexerInfo, static_scheme::scheme::Procedure};
5
6use super::nodes_reader::NodesReader;
7
8
9
10pub struct DynSchmError
11{
12 li: LexerInfo,
13 procedure: Option<Arc<Procedure>>,
14 msg: String,
15}
16
17
18impl fmt::Display for DynSchmError
19{
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
21 {
22 write!(f, "[dynamic_scheme] '{}', proc: '{}', error: '{}'",
23 self.li, self.procedure.as_ref().map_or("NONE", |f| f.get_name().as_str()), self.msg)
24 }
25}
26impl fmt::Debug for DynSchmError
27{
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
29 {
30 write!(f, "[dynamic_scheme] '{}', proc: '{}', error: '{}'",
31 self.li, self.procedure.as_ref().map_or("NONE", |f| f.get_name().as_str()), self.msg)
32 }
33}
34
35impl DynSchmError
36{
37 pub
38 fn new(li: LexerInfo, procedure: Option<Arc<Procedure>>, msg: String) -> Self
39 {
40 return Self{ li: li, procedure: procedure, msg: msg };
41 }
42
43 pub
44 fn new_text(msg: String) -> Self
45 {
46 return Self{ li: LexerInfo::notexistent(), procedure: None, msg: msg };
47 }
48
49
50 pub
51 fn new_lexer(e: LexerError) -> Self
52 {
53 return Self{ li: e.location, procedure: None, msg: e.message };
54 }
55
56 pub
57 fn new_nodes(nd: &NodesReader, msg: String) -> Self
58 {
59 return Self{ li: nd.get_base_li(), procedure: Some(nd.get_proc_info()), msg: msg };
60 }
61}
62
63pub type DynSchmRes<T> = Result<T, DynSchmError>;