trees_lang/compile/
errors.rs1use std::{error::Error, fmt};
2
3use super::{ArgPlug, CompilingBlock, EdgeFragment};
4
5#[derive(Debug, PartialEq, Eq)]
6pub enum CompileError {
8 NonUniqueStartBlock(Box<NonUniqueStartBlockError>),
10 DanglingArgEdge(Box<DanglingArgEdgeError>),
12}
13
14#[derive(Debug, PartialEq, Eq)]
15pub struct NonUniqueStartBlockError {
17 pub candinates: Vec<CompilingBlock>,
19}
20
21#[derive(Debug, PartialEq, Eq)]
22pub struct DanglingArgEdgeError {
24 pub block_of_arg_plug: CompilingBlock,
26 pub arg_plug: ArgPlug,
28 pub edge_fragments: Vec<EdgeFragment>,
30 pub dangling_position: (usize, usize),
34}
35
36impl fmt::Display for CompileError {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 match self {
39 CompileError::NonUniqueStartBlock(err) => write!(
40 f,
41 "The code must have exact one block which has no block-plug. Found: {}",
42 err.candinates.len() ),
44 CompileError::DanglingArgEdge(err) => write!(
45 f,
46 "The arg-plug on ({}, {}) has an arg-plug which is not connected to any block. Expected position: ({}, {})",
47 err.arg_plug.x,
48 err.arg_plug.y,
49 err.dangling_position.0,
50 err.dangling_position.1 ),
52 }
53 }
54}
55
56impl Error for CompileError {
57 fn source(&self) -> Option<&(dyn Error + 'static)> {
58 None
59 }
60}