1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use crate::formattedtext::FormattedText;

#[derive(Debug)]
pub enum DaisyError {

	// Parser errors
	//MissingCloseParen,
	ExtraCloseParen,
	EmptyGroup,
	Syntax,
	BadNumber,
	BadVariable,
	BadFunction,
	BadTuple,

	// Evaluation errors
	BadMath,
	TooBig,
	ZeroDivision,
	IncompatibleUnit,
	IncompatibleUnits(String, String),
	Undefined(String),
	EvaluationError,
	BadArguments(String, usize, usize)
}

impl DaisyError {
	pub fn text(&self) -> FormattedText {
		match self {
			//DaisyError::MissingCloseParen => {
			//	String::from("Missing close parenthesis")
			//},
			DaisyError::ExtraCloseParen => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Extra close parenthesis".to_string()
				);
			},
			DaisyError::EmptyGroup => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Groups can't be empty".to_string()
				);
			},
			DaisyError::Syntax => {
				return FormattedText::new(
					"[e]Syntax Error[n]".to_string()
				);
			},
			DaisyError::BadNumber => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Invalid number".to_string()
				);
			},
			DaisyError::BadVariable => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Bad variable name".to_string()
				);
			},
			DaisyError::BadFunction => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Bad function name".to_string()
				);
			},
			DaisyError::BadTuple => {
				return FormattedText::new(
					"[e]Syntax Error:[n] Bad tuple syntax".to_string()
				);
			},


			DaisyError::BadMath => {
				return FormattedText::new(
					"[e]Evaluation Error:[n] Failed to evaluate expression".to_string()
				);
			},
			DaisyError::TooBig => {
				return FormattedText::new(
					"[e]Evaluation Error:[n] Number too big".to_string()
				);
			},
			DaisyError::ZeroDivision => {
				return FormattedText::new(
					"[e]Evaluation Error:[n] Division by zero".to_string()
				);
			},
			DaisyError::IncompatibleUnit => {
				return FormattedText::new(
					"[e]Evaluation Error:[n] Incompatible unit".to_string()
				);
			},
			DaisyError::IncompatibleUnits(a, b) => {
				return FormattedText::new(format!(
					"[e]Evaluation Error:[n] Incompatible units ([c]{a}[n] and [c]{b}[n])"
				));
			},
			DaisyError::Undefined(s) => {
				return FormattedText::new(format!(
					"[e]Evaluation Error:[n] [c]{s}[n] is not defined"
				));
			},
			DaisyError::EvaluationError => {
				return FormattedText::new(
					"[e]Evaluation Error:[n] Could not evaluate".to_string()
				);
			},
			DaisyError::BadArguments(s, want, got) => {
				return FormattedText::new(format!(
					"[e]Evaluation Error:[n] [c]{s}[n] takes {want} argument{}, but it got {got}",
					if *want == 1 {""} else {"s"},
				));
			}
		}
	}
}