1#![allow(unused_macros)]
2
3use thiserror::Error;
4
5macro_rules! syntax_error {
7 ($err:expr $(,)?) => ({
8 anyhow::Error::new($crate::errors::SyntaxError($err.to_string()))
9 });
10 ($fmt:expr, $($arg:tt)*) => {
11 anyhow::Error::new($crate::errors::SyntaxError(format!($fmt, $($arg)*)))
12 };
13}
14
15macro_rules! interpreter_error {
17 ($err:expr $(,)?) => ({
18 anyhow::Error::new($crate::errors::InterpreterError($err.to_string()))
19 });
20 ($fmt:expr, $($arg:tt)*) => {
21 anyhow::Error::new($crate::errors::InterpreterError(format!($fmt, $($arg)*)))
22 };
23}
24
25macro_rules! template_error {
27 ($err:expr $(,)?) => ({
28 anyhow::Error::new($crate::errors::TemplateError($err.to_string()))
29 });
30 ($fmt:expr, $($arg:tt)*) => {
31 anyhow::Error::new($crate::errors::TemplateError(format!($fmt, $($arg)*)))
32 };
33}
34
35#[cfg(test)]
37macro_rules! assert_syntax_error {
38 ($left:expr, $right:expr) => ({
39 assert_eq!(
40 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::SyntaxError>().expect("Expected a SyntaxError"),
41 &$crate::errors::SyntaxError($right.to_string())
42 );
43 });
44 ($left:expr, $right:expr,) => ({
45 assert_syntax_error!($left, $right)
46 });
47 ($left:expr, $right:expr, $($arg:tt)+) => ({
48 assert_eq!(
49 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::SyntaxError>().expect("Expected a SyntaxError"),
50 &$crate::errors::SyntaxError($right.to_string()),
51 $($arg)*
52 );
53 });
54}
55
56#[cfg(test)]
58macro_rules! assert_interpreter_error {
59 ($left:expr, $right:expr) => ({
60 assert_eq!(
61 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::InterpreterError>().expect("Expected a InterpreterError"),
62 &$crate::errors::InterpreterError($right.to_string())
63 );
64 });
65 ($left:expr, $right:expr,) => ({
66 assert_interpreter_error!($left, $right)
67 });
68 ($left:expr, $right:expr, $($arg:tt)+) => ({
69 assert_eq!(
70 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::InterpreterError>().expect("Expected a InterpreterError"),
71 &$crate::errors::InterpreterError($right.to_string()),
72 $($arg)*
73 );
74 });
75}
76
77#[cfg(test)]
79macro_rules! assert_template_error {
80 ($left:expr, $right:expr) => ({
81 assert_eq!(
82 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::TemplateError>().expect("Expected a TemplateError"),
83 &$crate::errors::TemplateError($right.to_string())
84 );
85 });
86 ($left:expr, $right:expr,) => ({
87 assert_template_error!($left, $right)
88 });
89 ($left:expr, $right:expr, $($arg:tt)+) => ({
90 assert_eq!(
91 $left.expect_err("Expected an error, got").downcast_ref::<$crate::errors::TemplateError>().expect("Expected a TemplateError"),
92 &$crate::errors::TemplateError($right.to_string()),
93 $($arg)*
94 );
95 });
96}
97
98#[derive(Debug, Error, Eq, PartialEq, Clone)]
100#[error("Syntax Error: {0}")]
101pub struct SyntaxError(pub(crate) String);
102
103#[derive(Debug, Error, Eq, PartialEq, Clone)]
105#[error("Interpreter Error: {0}")]
106pub struct InterpreterError(pub(crate) String);
107
108#[derive(Debug, Error, Eq, PartialEq, Clone)]
110#[error("TemplateError: {0}")]
111pub struct TemplateError(pub(crate) String);