quantrs2_tytan/problem_dsl/
error.rs

1//! Error types for the problem DSL.
2
3use std::fmt;
4
5/// Parse error
6#[derive(Debug, Clone)]
7pub struct ParseError {
8    pub message: String,
9    pub line: usize,
10    pub column: usize,
11}
12
13impl fmt::Display for ParseError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        write!(
16            f,
17            "Parse error at line {}, column {}: {}",
18            self.line, self.column, self.message
19        )
20    }
21}
22
23impl std::error::Error for ParseError {}
24
25/// Type error
26#[derive(Debug, Clone)]
27pub struct TypeError {
28    pub message: String,
29    pub location: String,
30}
31
32impl fmt::Display for TypeError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        write!(f, "Type error at {}: {}", self.location, self.message)
35    }
36}
37
38impl std::error::Error for TypeError {}
39
40impl From<TypeError> for ParseError {
41    fn from(type_error: TypeError) -> Self {
42        Self {
43            message: type_error.message,
44            line: 0,
45            column: 0,
46        }
47    }
48}
49
50/// Compilation error
51#[derive(Debug, Clone)]
52pub struct CompileError {
53    pub message: String,
54    pub context: String,
55}
56
57impl fmt::Display for CompileError {
58    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59        write!(f, "Compilation error in {}: {}", self.context, self.message)
60    }
61}
62
63impl std::error::Error for CompileError {}