From 92dbff3cda66a2a677f0c2306bb8508c64884445 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 11 Jun 2026 10:43:24 -0700 Subject: Broke out error and renamed it. I like the new name, now it could be for all sorts. --- src/error.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..a2b6d96 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,45 @@ + +use core::error::Error; +use std::fmt; + +use crate::position::*; + +#[derive(Debug)] +pub struct CrimError { + position: Position, + what: String, +} + +impl CrimError { + pub fn new( position: Position, what: String ) -> Self { + CrimError { + position, + what, + } + } + + pub fn eos( context: &str ) -> Self { + CrimError { + 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 CrimError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Error parsing input: {}", "yeah") + } +} + +impl Error for CrimError { } + +pub type CrimResult = Result; -- cgit v1.2.3