plotnik_compiler/emit/
error.rs

1//! Error types for bytecode emission.
2
3use plotnik_core::Symbol;
4
5/// Error during bytecode emission.
6#[derive(Clone, Debug)]
7pub enum EmitError {
8    /// Query has validation errors (must be valid before emitting).
9    InvalidQuery,
10    /// Too many strings (exceeds u16 max).
11    TooManyStrings(usize),
12    /// Too many types (exceeds u16 max).
13    TooManyTypes(usize),
14    /// Too many type members (exceeds u16 max).
15    TooManyTypeMembers(usize),
16    /// Too many entrypoints (exceeds u16 max).
17    TooManyEntrypoints(usize),
18    /// Too many transitions (exceeds u16 max).
19    TooManyTransitions(usize),
20    /// Too many regexes (exceeds u16 max).
21    TooManyRegexes(usize),
22    /// String not found in interner.
23    StringNotFound(Symbol),
24    /// Regex compilation failed.
25    RegexCompile(String, String),
26    /// Compilation error.
27    Compile(crate::compile::CompileError),
28}
29
30impl std::fmt::Display for EmitError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Self::InvalidQuery => write!(f, "query has validation errors"),
34            Self::TooManyStrings(n) => write!(f, "too many strings: {n} (max 65534)"),
35            Self::TooManyTypes(n) => write!(f, "too many types: {n} (max 65533)"),
36            Self::TooManyTypeMembers(n) => write!(f, "too many type members: {n} (max 65535)"),
37            Self::TooManyEntrypoints(n) => write!(f, "too many entrypoints: {n} (max 65535)"),
38            Self::TooManyTransitions(n) => write!(f, "too many transitions: {n} (max 65535)"),
39            Self::TooManyRegexes(n) => write!(f, "too many regexes: {n} (max 65535)"),
40            Self::StringNotFound(sym) => write!(f, "string not found for symbol: {sym:?}"),
41            Self::RegexCompile(pat, err) => write!(f, "regex compile error for '{pat}': {err}"),
42            Self::Compile(e) => write!(f, "compilation error: {e}"),
43        }
44    }
45}
46
47impl std::error::Error for EmitError {}