#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum SyntaxGraphError {
EmptyAstGraph,
MissingRootNode,
MissingAstNode,
UnexpectedAstShape,
UnsupportedLanguage,
}
impl core::fmt::Display for SyntaxGraphError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter.write_str(match *self {
Self::EmptyAstGraph => "ast graph has no nodes",
Self::MissingRootNode => "ast graph has no root node at id 1",
Self::MissingAstNode => "a reader reached an id absent from the ast graph",
Self::UnexpectedAstShape => "a reader found an ast shape its grammar cannot produce",
Self::UnsupportedLanguage => "no syntax dispatcher is implemented for this language",
})
}
}
#[cfg(test)]
mod tests {
use super::SyntaxGraphError;
use alloc::string::ToString;
#[test]
fn every_error_renders_its_failure_mode() {
assert_eq!(
SyntaxGraphError::EmptyAstGraph.to_string(),
"ast graph has no nodes"
);
assert_eq!(
SyntaxGraphError::MissingRootNode.to_string(),
"ast graph has no root node at id 1"
);
assert_eq!(
SyntaxGraphError::MissingAstNode.to_string(),
"a reader reached an id absent from the ast graph"
);
assert_eq!(
SyntaxGraphError::UnexpectedAstShape.to_string(),
"a reader found an ast shape its grammar cannot produce"
);
assert_eq!(
SyntaxGraphError::UnsupportedLanguage.to_string(),
"no syntax dispatcher is implemented for this language"
);
}
}