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
use std::error::Error;
use std::fmt::{Display, Formatter};
use crate::evaluator::{SyntaxError, Context};
use crate::template::EvaluableMixedContent;
use crate::units::Position;
pub trait Compiler<T> {
type Item;
type ItemIterator: Iterator<Item = Self::Item>;
fn compile<C>(&self, content: C, context: Context) -> Result<String, CompilationError>
where C: EvaluableMixedContent<Item=Self::Item, IntoIter=Self::ItemIterator>;
}
#[derive(Debug, PartialEq)]
pub enum CompilationError {
EvaluationFailed {
error: SyntaxError,
position: Position,
source: String,
},
}
impl Error for CompilationError {}
impl Display for CompilationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}