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
use crate::parser;
use std::fmt;
use std::ops::Range;
#[derive(Debug)]
pub enum JsonPopError<'a> {
Parse(crate::parser::ParseError<'a>),
Io(std::io::Error),
TestError(crate::extra::test_utils::TestError<'a>),
}
#[derive(Debug)]
pub enum TopLevelError {
TestingError,
ParseError,
Io(std::io::Error),
}
impl<'a> From<JsonPopError<'a>> for TopLevelError {
fn from(it: JsonPopError<'a>) -> TopLevelError {
match it {
JsonPopError::Parse(_) => {
TopLevelError::ParseError
}
JsonPopError::Io(err) => TopLevelError::Io(err),
JsonPopError::TestError(_) => TopLevelError::TestingError,
}
}
}
#[derive(Debug)]
pub enum CompilationError {
LexicalError { range: Range<usize> },
NumericalError { range: Range<usize> },
UnterminatedStringLiteral { range: Range<usize> },
}
impl fmt::Display for CompilationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#?}", self)
}
}
impl<'a> fmt::Display for JsonPopError<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#?}", self)
}
}
impl<'a> From<std::io::Error> for JsonPopError<'a> {
fn from(err: std::io::Error) -> Self {
JsonPopError::Io(err)
}
}
impl<'a> From<parser::ParseError<'a>> for JsonPopError<'a> {
fn from(err: parser::ParseError<'a>) -> Self {
JsonPopError::Parse(err)
}
}