use thiserror::Error;
use super::LRConflictError;
#[derive(Error, Debug)]
pub enum GrammarAnalysisError {
#[error("Grammar contains left-recursions")]
LeftRecursion {
recursions: Vec<RecursiveNonTerminal>,
},
#[error("Grammar contains unreachable non-terminals")]
UnreachableNonTerminals {
non_terminals: Vec<RelatedHint>,
},
#[error("Grammar contains nonproductive non-terminals")]
NonProductiveNonTerminals {
non_terminals: Vec<RelatedHint>,
},
#[error("Maximum lookahead of {max_k} exceeded")]
MaxKExceeded {
max_k: usize,
},
#[error("LALR(1) parse table construction failed with conflicts")]
LALR1ParseTableConstructionFailed {
conflict: LRConflictError,
},
}
#[derive(Error, Debug)]
#[error("Recursive non-terminal #{number}: '{name}'")]
pub struct RecursiveNonTerminal {
pub number: usize,
pub name: String,
}
#[derive(Error, Debug)]
#[error("{topic}: {hint}")]
pub struct RelatedHint {
pub topic: String,
pub hint: String,
}