shm_rs/static_scheme/
error.rs1use core::fmt;
2use std::collections::HashSet;
3
4use crate::
5{
6 lexer::lexer_error::LexerError, LexerInfo
7};
8
9use super::{environment::EnvProcs, nodes_reader::NodesReader};
10
11#[derive(Debug, Clone)]
12pub struct StaticSchemeError
13{
14 pub msg: String,
15}
16
17impl StaticSchemeError
18{
19 pub
20 fn new(location: LexerInfo, proc_name: EnvProcs, msg: String) -> Self
21 {
22 return
23 StaticSchemeError
24 {
25 msg: format!("at '{}' procedure: '{}' {}", location, proc_name.as_str(), msg)
26 };
27 }
28
29 pub
30 fn new_nodes_reader(nnr: &NodesReader, msg: String) -> Self
31 {
32 return
33 StaticSchemeError
34 {
35 msg: format!("at '{}' procedure: '{}' {}", nnr.get_cur_or_base_li(), nnr.get_proc_name(), msg)
36 };
37 }
38
39 pub
40 fn concat_prefx_msg(mut self, msg: String) -> Self
41 {
42 self.msg = [msg.as_str(), self.msg.as_str()].join(" ");
43
44 return self;
45 }
46
47}
48
49
50impl fmt::Display for StaticSchemeError
51{
52 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
53 {
54 write!(f, "{}", self.msg)
55 }
56}
57
58
59pub type StaticSchemeRes<T> = Result<T, StaticSchemeError>;
60
61
62pub
63fn convert_list<T: fmt::Display>(extr: &[T]) -> String
64{
65 let recs: Vec<String> = extr.iter().map(|v| format!("{}", v)).collect();
66
67 return recs.join(" ");
68}
69
70pub
71fn convert_hashset<T: fmt::Display>(extr: &HashSet<T>, sep: &str) -> String
72{
73 let recs: Vec<String> = extr.iter().map(|v| format!("{}", v)).collect();
74
75 return recs.join(sep);
76}
77