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
//! Error types for table generation and compression.
/// Errors produced by table generation and compression.
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum TableGenError {
/// Invalid input was provided to a table generation function.
#[error("invalid input: {0}")]
InvalidInput(&'static str),
/// Automaton construction failed during table generation.
#[error("automaton build failed: {0}")]
Automaton(String),
/// Table compression algorithm encountered an error.
#[error("compression failed: {0}")]
Compression(String),
/// General table generation failure, often from upstream errors.
#[error("table generation failed: {0}")]
TableGeneration(String),
/// The table structure is invalid or corrupted.
#[error("invalid table structure: {0}")]
InvalidTable(String),
/// Symbol index is out of bounds for the grammar.
#[error("symbol index out of bounds: {0}")]
InvalidSymbolIndex(usize),
/// State index is out of bounds for the parse table.
#[error("state index out of bounds: {0}")]
InvalidStateIndex(usize),
/// The grammar is empty and cannot be processed.
#[error("empty grammar")]
EmptyGrammar,
/// Grammar validation failed before table generation.
#[error("grammar validation failed: {0}")]
ValidationError(String),
/// I/O error occurred during file operations.
#[error(transparent)]
Io(#[from] std::io::Error),
/// JSON serialization/deserialization error.
#[error(transparent)]
Json(#[from] serde_json::Error),
/// Error bubbled from the GLR automaton builder.
#[error(transparent)]
Glr(#[from] adze_glr_core::GLRError),
/// Error bubbled from the IR layer.
#[error(transparent)]
Ir(#[from] adze_ir::IrError),
}
/// Convenience type alias for TableGen results.
pub type Result<T> = std::result::Result<T, TableGenError>;
impl From<String> for TableGenError {
fn from(s: String) -> Self {
TableGenError::TableGeneration(s)
}
}
impl From<&str> for TableGenError {
fn from(s: &str) -> Self {
TableGenError::TableGeneration(s.to_string())
}
}