tree-sitter/cli/src/error.rs

25 lines
561 B
Rust
Raw Normal View History

2018-12-05 12:50:12 -08:00
#[derive(Debug)]
pub struct Error(pub String);
2018-12-05 12:50:12 -08:00
pub type Result<T> = std::result::Result<T, Error>;
2018-12-08 13:44:11 -08:00
impl Error {
pub fn grammar(message: &str) -> Self {
Error(format!("Grammar error: {}", message))
2018-12-08 13:44:11 -08:00
}
pub fn regex(message: &str) -> Self {
Error(format!("Regex error: {}", message))
}
pub fn undefined_symbol(name: &str) -> Self {
Error(format!("Undefined symbol `{}`", name))
2018-12-08 13:44:11 -08:00
}
}
2018-12-05 12:50:12 -08:00
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Error(error.to_string())
2018-12-05 12:50:12 -08:00
}
}