From 5602585e7afe431f25e68f30ac54761db2a710e5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 19 Aug 2026 10:06:25 -0700 Subject: Renamed to DeepCrow --- deepcrow/src/error.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 deepcrow/src/error.rs (limited to 'deepcrow/src/error.rs') diff --git a/deepcrow/src/error.rs b/deepcrow/src/error.rs new file mode 100644 index 0000000..8fe21f0 --- /dev/null +++ b/deepcrow/src/error.rs @@ -0,0 +1,59 @@ + +use core::error::Error; +use std::fmt; + +use crate::position::*; + +#[derive(Debug)] +pub struct DeepCrowError { + position: Position, + what: String, +} + +impl DeepCrowError { + pub fn parse( position: Position, what: String ) -> Self { + Self { + position, + what, + } + } + + pub fn other(what: String) -> Self { + Self { + position: Position::none(), + what, + } + } + + pub fn broken( position: Position, what: &str ) -> Self { + Self { + position, + what: format!("Broken parser? {}", what), + } + } + + pub fn eos( context: &str ) -> Self { + Self { + position: Position::none(), + what: format!("Premature end of stream while looking for {}", context), + } + } + + pub fn what(&self) -> &str { + &self.what + } + + pub fn start(&self) -> &Position { + &self.position + } +} + +impl fmt::Display for DeepCrowError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Error parsing input: {}", "yeah") + } +} + +impl Error for DeepCrowError { } + +pub type Result = std::result::Result; -- cgit v1.2.3