From cd2daf6fef343781c737d07818b2bbc6a4ed206b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 15 Dec 2022 23:15:27 -0500 Subject: [PATCH] Replace all TODOs wanting a custom error with a generic custom error. --- src/parser/error.rs | 2 +- src/parser/nom_context.rs | 14 +++++++------- src/parser/text_element_parser.rs | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/parser/error.rs b/src/parser/error.rs index 274cc3d..6598f40 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -11,7 +11,7 @@ pub enum CustomError { } #[derive(Debug, PartialEq)] -pub struct MyError(I); +pub struct MyError(pub I); impl ParseError for CustomError { fn from_error_kind(input: I, kind: ErrorKind) -> Self { diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 02daccb..eea70bd 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -6,6 +6,7 @@ use nom::error::VerboseError; use nom::IResult; use super::error::CustomError; +use super::error::MyError; use super::list::List; use super::list::Node; use super::token::Token; @@ -63,12 +64,12 @@ impl<'r, 's> ContextTree<'r, 's> { if local_result.is_ok() { return local_result; } - // TODO: Make this a custom error - not(take(0usize))(i)?; + // TODO: Make this a specific error instead of just a generic MyError + return Err(nom::Err::Error(CustomError::MyError(MyError("NoExit")))); } ChainBehavior::IgnoreParent(None) => { - // TODO: Make this a custom error - not(take(0usize))(i)?; + // TODO: Make this a specific error instead of just a generic MyError + return Err(nom::Err::Error(CustomError::MyError(MyError("NoExit")))); } }; } @@ -77,9 +78,8 @@ impl<'r, 's> ContextTree<'r, 's> { ContextElement::Context(_) => {} }; } - // TODO: Make this a custom error - not(take(0usize))(i)?; - unreachable!() + // TODO: Make this a specific error instead of just a generic MyError + return Err(nom::Err::Error(CustomError::MyError(MyError("NoExit")))); } } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 9a30f6c..24f86ed 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -2,6 +2,8 @@ use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; +use super::error::CustomError; +use super::error::MyError; use super::nom_context::ChainBehavior; use super::nom_context::ContextElement; use super::nom_context::ContextTree; @@ -181,9 +183,8 @@ pub fn context_bold_start<'s, 'r>( if can_start_bold(context) { recognize(bold_start)(input) } else { - // TODO: Make this a custom error - not(take(0usize))(input)?; - unreachable!() + // TODO: Make this a specific error instead of just a generic MyError + return Err(nom::Err::Error(CustomError::MyError(MyError("Cannot start bold")))); } }