From 6cc46751f903963162a7874747a051f653ee4c31 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 24 Jun 2026 23:38:05 +0200 Subject: [PATCH] Removed error recovery --- crates/parser/src/error.rs | 90 +++++++------------------------------- 1 file changed, 16 insertions(+), 74 deletions(-) diff --git a/crates/parser/src/error.rs b/crates/parser/src/error.rs index 592fa7e..dd635f2 100644 --- a/crates/parser/src/error.rs +++ b/crates/parser/src/error.rs @@ -4,20 +4,19 @@ use pest::iterators::Pair; use crate::Rule; -pub type AstResult<'a, T, ET = T> = Result>; +pub type AstResult<'a, T> = Result>; #[derive(Debug, Clone)] -pub enum ParseError<'a, T> { +pub enum ParseError<'a> { PreAst(pest::error::Error), - Ast(AstError<'a, T>), + Ast(AstError<'a>), } #[derive(Debug, Clone)] -pub struct AstError<'a, T> { +pub struct AstError<'a> { pub span: pest::Span<'a>, pub error_code: ErrorCode, pub error_message: String, - pub recovered: Option, } #[derive(Debug, Clone)] @@ -27,30 +26,21 @@ pub enum ErrorCode { Module, } -impl From> for ParseError<'_, T> { +impl From> for ParseError<'_> { fn from(value: pest::error::Error) -> Self { Self::PreAst(value) } } -impl<'a, T> From> for ParseError<'a, T> { - fn from(value: AstError<'a, T>) -> Self { +impl<'a> From> for ParseError<'a> { + fn from(value: AstError<'a>) -> Self { Self::Ast(value) } } -impl<'a, F> AstError<'a, F> { - pub fn get(self) -> AstError<'a, T> { - AstError { - span: self.span, - error_code: self.error_code, - error_message: self.error_message, - recovered: None, - } - } - +impl<'a> AstError<'a> { #[track_caller] - pub fn bug_unimplemented(pair: Pair<'a, Rule>) -> AstResult<'a, T, F> { + pub fn bug_unimplemented(pair: Pair<'a, Rule>) -> AstResult<'a, T> { let loc = std::panic::Location::caller(); Err(Self { @@ -62,7 +52,6 @@ impl<'a, F> AstError<'a, F> { loc.file(), loc.line(), ), - recovered: None, }) } } @@ -72,21 +61,6 @@ pub trait IntoErr { fn get_map(self, m: impl Fn(FA) -> FR) -> T; } -impl<'a, T, TE, TE2> IntoErr, TE, TE2> for AstResult<'a, T, TE> { - fn get(self) -> AstResult<'a, T, TE2> { - self.map_err(AstError::get) - } - - fn get_map(self, m: impl Fn(TE) -> TE2) -> AstResult<'a, T, TE2> { - self.map_err(|e| AstError { - span: e.span, - error_code: e.error_code, - error_message: e.error_message, - recovered: e.recovered.map(m), - }) - } -} - pub trait GetLength { fn len(&self) -> usize; } @@ -97,24 +71,24 @@ impl GetLength for Result, E> { } } -pub fn collect_recovered<'a, T: Debug, ET>( +pub fn collect_recovered<'a, T: Debug>( pairs: impl Iterator>, -) -> AstResult<'a, Vec, Vec> +) -> AstResult<'a, Vec> where - T: TryFrom, Error = AstError<'a, ET>>, + T: TryFrom, Error = AstError<'a>>, { collect_recovered_map(pairs, T::try_from) } -pub fn collect_recovered_map<'a, T: Debug, F, ET>( +pub fn collect_recovered_map<'a, T: Debug, F>( pairs: impl Iterator>, f: F, -) -> AstResult<'a, Vec, Vec> +) -> AstResult<'a, Vec> where - F: Fn(pest::iterators::Pair<'a, Rule>) -> AstResult<'a, T, ET>, + F: Fn(pest::iterators::Pair<'a, Rule>) -> AstResult<'a, T>, { let mut items = Vec::new(); - let mut last_error: Option> = None; + let mut last_error: Option> = None; for pair in pairs { match f(pair) { @@ -130,39 +104,7 @@ where span: ast_err.span, error_code: ast_err.error_code, error_message: ast_err.error_message, - recovered: Some(items), }), None => Ok(items), } } - -pub struct AstErrorAnalyzer<'a, T>(pub Option>); - -impl<'a, T> AstErrorAnalyzer<'a, T> { - pub fn get>( - &mut self, - r: AstResult<'a, V, V2>, - ) -> AstResult<'a, V, V2> { - if let Err(e) = r { - self.0 = Some(e.clone().get()); - - if let Some(recovered) = e.recovered { - Ok(recovered.into()) - } else { - Err(e) - } - } else { - r - } - } - - pub fn build(self, v: T) -> AstResult<'a, T> { - if let Some(mut e) = self.0 { - e.recovered = Some(v); - - Err(e) - } else { - Ok(v) - } - } -}