1use crate::*;
2
3type Rows = usize;
9type Cols = usize;
10pub type ParserErrorReport = Vec<ParserErrorContext>;
11
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13#[derive(Clone, Debug, Eq, PartialEq, Hash)]
14pub struct MechError{
15 pub id: u32,
16 pub file: String,
17 pub tokens: Vec<Token>,
18 pub kind: MechErrorKind,
19 pub msg: String,
20}
21
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23#[derive(Clone, Debug, Eq, PartialEq, Hash)]
24pub struct ParserErrorContext {
25 pub cause_rng: SourceRange,
26 pub err_message: String,
27 pub annotation_rngs: Vec<SourceRange>,
28}
29
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31#[derive(Clone, Debug, Eq, PartialEq, Hash)]
32pub enum MechErrorKind {
33 UndefinedField(u64), UndefinedVariable(u64), UndefinedKind(u64), MissingTable(u64), WrongTableColumnKind,
38 MissingBlock(u64), PendingExpression, PendingTable(u64), DimensionMismatch(Vec<(Rows,Cols)>), KindMismatch(ValueKind,ValueKind),
43 UnhandledIndexKind,
44 LinearSubscriptOutOfBounds((Rows,Rows)), IndexOutOfBounds,
49 MissingFunction(u64), ZeroIndex, VariableRedefined(u64),
55 NotMutable(u64),
56 BlockDisabled,
57 IoError,
58 UnhandledFormulaOperator(FormulaOperator),
59 FeatureNotEnabled(String), GenericError(String),
61 FileNotFound(String),
62 Unhandled,
63 OutputUndefinedInFunctionBody(u64),
64 UnknownFunctionArgument(u64),
65 UnknownColumnKind(u64),
66 UnknownEnumVairant(u64,u64),
67 UnableToConvertValueKind,
68 UnhandledFunctionArgumentKind,
69 CouldNotAssignKindToValue,
70 ExpectedNumericForSize, MatrixMustHaveHomogenousKind, IncorrectNumberOfArguments,
73 TooManyInputArguments(usize,usize), ParserError(ParserErrorReport, String),
76 InvalidCapabilityToken,
78 UnknownReplCommand(String),
79 NoCode,
80 None,
81}
82
83#[cfg(not(feature = "no_std"))]
84impl From<std::io::Error> for MechError{
85 fn from(n: std::io::Error) -> MechError{
86 MechError{
87 id: line!(),
88 file: file!().to_string(),
89 tokens: vec![],
90 kind: MechErrorKind::IoError,
91 msg: n.to_string(),
92 }
93 }
94}
95
96#[cfg(feature = "no_std")]
97impl From<()> for MechError {
98 fn from(_: ()) -> Self {
99 MechError {
100 id: line!(),
101 file: file!().to_string(),
102 tokens: Vec::new(),
103 kind: MechErrorKind::IoError,
104 msg: "embedded-io error".into(),
105 }
106 }
107}
108
109