From 8417b5fc9da40ebb8aef2c896753a261d844d2fc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 09:27:15 -0400 Subject: [PATCH 1/6] Add an owned string entry for CustomError. --- src/error/error.rs | 1 + src/parser/org_source.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/error/error.rs b/src/error/error.rs index b7e1481..43615de 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -6,6 +6,7 @@ pub(crate) type Res = IResult>; #[derive(Debug)] pub enum CustomError { + Text(String), MyError(MyError<&'static str>), Nom(I, ErrorKind), IO(std::io::Error), diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index 3e72829..058ec62 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -402,6 +402,7 @@ impl<'s> From>> for CustomError<&'s str> { CustomError::Nom(input, error_kind) => CustomError::Nom(input.into(), error_kind), CustomError::IO(err) => CustomError::IO(err), CustomError::BoxedError(err) => CustomError::BoxedError(err), + CustomError::Text(err) => CustomError::Text(err), } } } From c9d7251e3b4e56e7c5ee817e257f873cabd5411d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 09:45:18 -0400 Subject: [PATCH 2/6] Begin removing the MyError type. --- src/context/context.rs | 1 - src/error/error.rs | 22 +++++++----------- src/error/mod.rs | 1 - src/parser/babel_call.rs | 1 - src/parser/citation_reference.rs | 1 - src/parser/comment.rs | 1 - src/parser/document.rs | 2 -- src/parser/drawer.rs | 1 - src/parser/dynamic_block.rs | 1 - src/parser/element_parser.rs | 1 - src/parser/entity.rs | 1 - src/parser/footnote_definition.rs | 1 - src/parser/footnote_reference.rs | 1 - src/parser/greater_block.rs | 4 +++- src/parser/headline.rs | 1 - src/parser/inline_babel_call.rs | 1 - src/parser/inline_source_block.rs | 1 - src/parser/keyword.rs | 1 - src/parser/latex_fragment.rs | 1 - src/parser/lesser_block.rs | 1 - src/parser/line_break.rs | 1 - src/parser/object_parser.rs | 1 - src/parser/org_source.rs | 31 ------------------------- src/parser/plain_link.rs | 1 - src/parser/plain_list.rs | 1 - src/parser/plain_text.rs | 1 - src/parser/property_drawer.rs | 1 - src/parser/radio_link.rs | 1 - src/parser/regular_link.rs | 1 - src/parser/subscript_and_superscript.rs | 1 - src/parser/target.rs | 1 - src/parser/text_markup.rs | 1 - src/parser/util.rs | 1 - 33 files changed, 12 insertions(+), 76 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index bff8fb3..1de2aa5 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -9,7 +9,6 @@ use super::list::List; use super::DynContextMatcher; use super::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::OrgSource; diff --git a/src/error/error.rs b/src/error/error.rs index 43615de..b338a4f 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -2,23 +2,19 @@ use nom::error::ErrorKind; use nom::error::ParseError; use nom::IResult; -pub(crate) type Res = IResult>; +pub(crate) type Res = IResult; #[derive(Debug)] -pub enum CustomError { +pub enum CustomError { Text(String), - MyError(MyError<&'static str>), - Nom(I, ErrorKind), + Static(&'static str), IO(std::io::Error), BoxedError(Box), } -#[derive(Debug)] -pub struct MyError(pub(crate) I); - -impl ParseError for CustomError { +impl ParseError for CustomError { fn from_error_kind(input: I, kind: ErrorKind) -> Self { - CustomError::Nom(input, kind) + CustomError::Text(format!("{:?} {:?}", kind, input)) } fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self { @@ -27,19 +23,19 @@ impl ParseError for CustomError { } } -impl From for CustomError { +impl From for CustomError { fn from(value: std::io::Error) -> Self { CustomError::IO(value) } } -impl From<&'static str> for CustomError { +impl From<&'static str> for CustomError { fn from(value: &'static str) -> Self { - CustomError::MyError(MyError(value)) + CustomError::Static(value) } } -impl From> for CustomError { +impl From> for CustomError { fn from(value: Box) -> Self { CustomError::BoxedError(value) } diff --git a/src/error/mod.rs b/src/error/mod.rs index 23cd35f..43b5794 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -1,5 +1,4 @@ #[allow(clippy::module_inception)] mod error; pub(crate) use error::CustomError; -pub(crate) use error::MyError; pub(crate) use error::Res; diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index 1f2447b..db50a25 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -21,7 +21,6 @@ use super::OrgSource; use crate::context::Matcher; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::org_line_ending; diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 4060de7..9598707 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -20,7 +20,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::object_parser::minimal_set_object; use crate::parser::util::exit_matcher_parser; diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 556b304..828dbf7 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -19,7 +19,6 @@ use crate::context::parser_with_context; use crate::context::ContextElement; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::immediate_in_section; diff --git a/src/parser/document.rs b/src/parser/document.rs index 9b4b54c..8e0ca88 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -19,9 +19,7 @@ use crate::context::GlobalSettings; use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; -use crate::parser::org_source::convert_error; use crate::parser::util::blank_line; use crate::types::AstNode; use crate::types::Document; diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index f430c84..9d1dbfd 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -19,7 +19,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; use crate::parser::util::blank_line; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 70cf5e8..c170acb 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -26,7 +26,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; use crate::parser::util::blank_line; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 0337559..ca553ee 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -30,7 +30,6 @@ use super::table::detect_table; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::macros::ak_element; use crate::parser::macros::element; diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 2fa1966..3ae0472 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -13,7 +13,6 @@ use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::EntityDefinition; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Entity; diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index f888a27..f447def 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -22,7 +22,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; use crate::parser::util::blank_line; diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 10daf42..76db35b 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -20,7 +20,6 @@ use crate::context::ExitMatcherNode; use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::footnote_definition::label; use crate::parser::object_parser::standard_set_object; diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 160d50f..5e8af14 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -28,7 +28,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; use crate::parser::util::blank_line; @@ -232,6 +231,9 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>( context_name: &'c str, ) -> Res, (&'s str, Vec>)> { if in_section(context, context_name) { + return Err(CustomError::Static( + "Cannot nest objects of the same element", + )); return Err(nom::Err::Error(CustomError::MyError(MyError( "Cannot nest objects of the same element", )))); diff --git a/src/parser/headline.rs b/src/parser/headline.rs index 98088c0..25663d1 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -29,7 +29,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::object_parser::standard_set_object; use crate::parser::util::blank_line; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 68ae9f6..a87cc7c 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -19,7 +19,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 3379b5b..0611cb9 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -21,7 +21,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 4789b2e..b9445fb 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -25,7 +25,6 @@ use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::macros::element; use crate::parser::util::start_of_line; diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 9e217e5..6febdcf 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -17,7 +17,6 @@ use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 8fe26e1..91aa6b7 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -27,7 +27,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::object_parser::standard_set_object; use crate::parser::util::blank_line; diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index fef8940..5e1dc06 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -7,7 +7,6 @@ use nom::multi::many0; use super::org_source::OrgSource; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::LineBreak; diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 7298451..5603a35 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -4,7 +4,6 @@ use super::regular_link::regular_link; use super::subscript_and_superscript::detect_subscript_or_superscript; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::angle_link::angle_link; use crate::parser::citation::citation; diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index 058ec62..be27b48 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -10,9 +10,6 @@ use nom::InputTakeAtPosition; use nom::Offset; use nom::Slice; -use crate::error::CustomError; -use crate::error::MyError; - pub(crate) type BracketDepth = i16; #[derive(Copy, Clone, PartialEq)] @@ -385,34 +382,6 @@ impl<'n, 's> FindSubstring<&'n str> for OrgSource<'s> { } } -pub(crate) fn convert_error<'a, I: Into>>( - err: nom::Err, -) -> nom::Err> { - match err { - nom::Err::Incomplete(needed) => nom::Err::Incomplete(needed), - nom::Err::Error(err) => nom::Err::Error(err.into()), - nom::Err::Failure(err) => nom::Err::Failure(err.into()), - } -} - -impl<'s> From>> for CustomError<&'s str> { - fn from(value: CustomError>) -> Self { - match value { - CustomError::MyError(err) => CustomError::MyError(err), - CustomError::Nom(input, error_kind) => CustomError::Nom(input.into(), error_kind), - CustomError::IO(err) => CustomError::IO(err), - CustomError::BoxedError(err) => CustomError::BoxedError(err), - CustomError::Text(err) => CustomError::Text(err), - } - } -} - -impl<'s> From>> for MyError<&'s str> { - fn from(value: MyError>) -> Self { - MyError(value.0.into()) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index f8b0cb3..f6fec5e 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -36,7 +36,6 @@ use crate::context::ExitMatcherNode; use crate::context::Matcher; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 7fffd18..4829d56 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -32,7 +32,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 0af1c67..6cc1915 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -20,7 +20,6 @@ use super::util::org_space_or_line_ending; use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::types::Object; use crate::types::PlainText; diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 8f9ae20..284ceb5 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -21,7 +21,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 9951881..888efaf 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -21,7 +21,6 @@ use crate::context::ExitMatcherNode; use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Object; diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index e464c4c..d509611 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -43,7 +43,6 @@ use crate::context::ExitMatcherNode; use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::types::LinkType; use crate::types::Object; diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 0851ea7..1d69590 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -26,7 +26,6 @@ use crate::context::ExitMatcherNode; use crate::context::Matcher; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Object; diff --git a/src/parser/target.rs b/src/parser/target.rs index 6ab0e61..f139b66 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -13,7 +13,6 @@ use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Target; diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 6606ad5..7f02b93 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -34,7 +34,6 @@ use crate::context::ExitMatcherNode; use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::parser::radio_link::rematch_target; use crate::parser::util::exit_matcher_parser; diff --git a/src/parser/util.rs b/src/parser/util.rs index 95155a6..f80e1df 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -20,7 +20,6 @@ use crate::context::parser_with_context; use crate::context::ContextElement; use crate::context::RefContext; use crate::error::CustomError; -use crate::error::MyError; use crate::error::Res; use crate::types::IndentationLevel; From 77e6c22ad8530009d06bc1de2abc1c33461d72ff Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:09:37 -0400 Subject: [PATCH 3/6] Continue removing MyError. --- src/context/context.rs | 2 +- src/parser/babel_call.rs | 4 +--- src/parser/citation_reference.rs | 4 +--- src/parser/comment.rs | 4 ++-- src/parser/drawer.rs | 4 ++-- src/parser/dynamic_block.rs | 4 ++-- src/parser/element_parser.rs | 8 ++----- src/parser/entity.rs | 2 +- src/parser/footnote_definition.rs | 4 ++-- src/parser/footnote_reference.rs | 4 ++-- src/parser/greater_block.rs | 4 ++-- src/parser/headline.rs | 4 +--- src/parser/inline_babel_call.rs | 8 ++----- src/parser/inline_source_block.rs | 6 ++--- src/parser/keyword.rs | 12 +++------- src/parser/latex_fragment.rs | 8 +++---- src/parser/lesser_block.rs | 2 +- src/parser/line_break.rs | 8 +++---- src/parser/object_parser.rs | 32 ++++++++++--------------- src/parser/plain_link.rs | 16 +++++-------- src/parser/plain_list.rs | 8 +++---- src/parser/plain_text.rs | 4 ++-- src/parser/property_drawer.rs | 4 ++-- src/parser/radio_link.rs | 8 +++---- src/parser/regular_link.rs | 4 +--- src/parser/subscript_and_superscript.rs | 8 +++---- src/parser/target.rs | 4 ++-- src/parser/text_markup.rs | 20 ++++++++-------- src/parser/util.rs | 12 ++++------ 29 files changed, 84 insertions(+), 128 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index 1de2aa5..98ea66d 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -122,7 +122,7 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> { } } // TODO: Make this a specific error instead of just a generic MyError - return Err(nom::Err::Error(CustomError::MyError(MyError("NoExit")))); + return Err(nom::Err::Error(CustomError::Static("NoExit"))); } /// Indicates if elements should consume the whitespace after them. diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index db50a25..0310505 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -216,9 +216,7 @@ fn impl_balanced_bracket< } if fail_parser(remaining).is_ok() { - return Err(nom::Err::Error(CustomError::MyError(MyError( - "Fail parser matched.", - )))); + return Err(nom::Err::Error(CustomError::Static("Fail parser matched."))); } let (remain, _) = anychar(remaining)?; diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 9598707..9d769f7 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -198,9 +198,7 @@ where let pre_bracket_depth = input.get_bracket_depth(); let (remaining, output) = inner(input)?; if remaining.get_bracket_depth() - pre_bracket_depth != 0 { - return Err(nom::Err::Error(CustomError::MyError(MyError( - "UnbalancedBrackets", - )))); + return Err(nom::Err::Error(CustomError::Static("UnbalancedBrackets"))); } Ok((remaining, output)) } diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 828dbf7..7523037 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -34,9 +34,9 @@ pub(crate) fn comment<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, Comment<'s>> { if immediate_in_section(context, "comment") { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } let parser_context = ContextElement::Context("comment"); let parser_context = context.with_additional_node(&parser_context); diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 9d1dbfd..d440f54 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -47,9 +47,9 @@ where AK: IntoIterator>, { if immediate_in_section(context, "drawer") { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } start_of_line(remaining)?; let (remaining, _leading_whitespace) = space0(remaining)?; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index c170acb..9a8e1cb 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -53,9 +53,9 @@ where AK: IntoIterator>, { if immediate_in_section(context, "dynamic block") { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } start_of_line(remaining)?; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index ca553ee..5cf4729 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -250,9 +250,7 @@ fn _element<'b, 'g, 'r, 's>( ); } - Err(nom::Err::Error(CustomError::MyError(MyError( - "No element.", - )))) + Err(nom::Err::Error(CustomError::Static("No element."))) } pub(crate) const fn detect_element( @@ -322,7 +320,5 @@ fn _detect_element<'b, 'g, 'r, 's>( return Ok((input, ())); } - Err(nom::Err::Error(CustomError::MyError(MyError( - "No element detected.", - )))) + Err(nom::Err::Error(CustomError::Static("No element detected."))) } diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 3ae0472..57ce58a 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -68,7 +68,7 @@ fn name<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError("NoEntity")))) + Err(nom::Err::Error(CustomError::Static("NoEntity"))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index f447def..e263c17 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -47,9 +47,9 @@ where AK: IntoIterator>, { if immediate_in_section(context, "footnote definition") { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } start_of_line(remaining)?; // Cannot be indented. diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 76db35b..2823ad7 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -175,9 +175,9 @@ fn _footnote_definition_end<'b, 'g, 'r, 's>( let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { // Its impossible for the next character to end the footnote reference definition if we're any amount of brackets deep - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "NoFootnoteReferenceDefinitionEnd", - )))); + ))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing bracket should end the footnote definition. diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 5e8af14..4fd3d72 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -234,9 +234,9 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>( return Err(CustomError::Static( "Cannot nest objects of the same element", )); - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } let exit_with_name = greater_block_end(name); let (remaining, _nl) = tuple((space0, line_ending))(input)?; diff --git a/src/parser/headline.rs b/src/parser/headline.rs index 25663d1..ea98acc 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -274,9 +274,7 @@ fn heading_keyword<'b, 'g, 'r, 's>( return Ok((remaining, (TodoKeywordType::Done, ent))); } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "NoTodoKeyword", - )))) + Err(nom::Err::Error(CustomError::Static("NoTodoKeyword"))) } } diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index a87cc7c..f059da0 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -130,9 +130,7 @@ fn _header_end<'b, 'g, 'r, 's>( let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { // Its impossible for the next character to end the header if we're any amount of bracket deep - return Err(nom::Err::Error(CustomError::MyError(MyError( - "NoHeaderEnd", - )))); + return Err(nom::Err::Error(CustomError::Static("NoHeaderEnd"))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing bracket should end the header. @@ -182,9 +180,7 @@ fn _argument_end<'b, 'g, 'r, 's>( let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth; if current_depth > 0 { // Its impossible for the next character to end the argument if we're any amount of parenthesis deep - return Err(nom::Err::Error(CustomError::MyError(MyError( - "NoArgumentEnd", - )))); + return Err(nom::Err::Error(CustomError::Static("NoArgumentEnd"))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing parenthesis should end the argument. diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 0611cb9..f0e22a7 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -124,9 +124,7 @@ fn _header_end<'b, 'g, 'r, 's>( let current_depth = input.get_bracket_depth() - starting_bracket_depth; if current_depth > 0 { // Its impossible for the next character to end the header if we're any amount of bracket deep - return Err(nom::Err::Error(CustomError::MyError(MyError( - "NoHeaderEnd", - )))); + return Err(nom::Err::Error(CustomError::Static("NoHeaderEnd"))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing bracket should end the header. @@ -186,7 +184,7 @@ fn _body_end<'b, 'g, 'r, 's>( let current_depth = input.get_brace_depth() - starting_brace_depth; if current_depth > 0 { // Its impossible for the next character to end the body if we're any amount of brace deep - return Err(nom::Err::Error(CustomError::MyError(MyError("NoBodyEnd")))); + return Err(nom::Err::Error(CustomError::Static("NoBodyEnd"))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing brace should end the body. diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index b9445fb..e19c4e9 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -151,9 +151,7 @@ fn affiliated_key<'b, 'g, 'r, 's>( element!(dual_affiliated_key, context, input); element!(plain_affiliated_key, context, input); element!(export_keyword, input); - Err(nom::Err::Error(CustomError::MyError(MyError( - "No affiliated key.", - )))) + Err(nom::Err::Error(CustomError::Static("No affiliated key."))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -174,9 +172,7 @@ fn plain_affiliated_key<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "NoKeywordKey", - )))) + Err(nom::Err::Error(CustomError::Static("NoKeywordKey"))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -197,9 +193,7 @@ fn dual_affiliated_key<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "NoKeywordKey", - )))) + Err(nom::Err::Error(CustomError::Static("NoKeywordKey"))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 6febdcf..e4ade8a 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -208,9 +208,9 @@ fn pre<'b, 'g, 'r, 's>( ) -> Res, ()> { let preceding_character = input.get_preceding_character(); if let Some('$') = preceding_character { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre character for dollar char fragment.", - )))); + ))); } Ok((input, ())) } @@ -282,9 +282,9 @@ fn close_border<'b, 'g, 'r, 's>( match preceding_character { Some(c) if !c.is_whitespace() && !".,;$".contains(c) => Ok((input, ())), _ => { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre character for dollar char fragment.", - )))); + ))); } } } diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 91aa6b7..9f99289 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -603,7 +603,7 @@ fn _example_src_switches<'s>( } } if !matched_a_word { - return Err(nom::Err::Error(CustomError::MyError(MyError("No words.")))); + return Err(nom::Err::Error(CustomError::Static("No words."))); } let remaining = last_match_remaining; diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 5e1dc06..f23e525 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -44,9 +44,9 @@ fn pre<'b, 'g, 'r, 's>( match preceding_character { // If None, we are at the start of the file None | Some('\\') => { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre character for line break.", - )))); + ))); } _ => {} }; @@ -54,9 +54,9 @@ fn pre<'b, 'g, 'r, 's>( let current_line = input.text_since_line_break(); let is_non_empty_line = current_line.chars().any(|c| !c.is_whitespace()); if !is_non_empty_line { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre line for line break.", - )))); + ))); } Ok((input, ())) diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 5603a35..c7e15d9 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -42,7 +42,7 @@ pub(crate) fn standard_set_object<'b, 'g, 'r, 's>( input, Object::PlainText ); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -60,7 +60,7 @@ pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>( input, Object::PlainText ); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -102,7 +102,7 @@ fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( element!(angle_link, context, input, Object::AngleLink); element!(org_macro, context, input, Object::OrgMacro); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -118,7 +118,7 @@ fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( element!(entity, context, input, Object::Entity); element!(latex_fragment, context, input, Object::LatexFragment); element!(text_markup, context, input); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -136,9 +136,7 @@ pub(crate) fn detect_standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( return Ok((input, ())); } - return Err(nom::Err::Error(CustomError::MyError(MyError( - "No object detected.", - )))); + return Err(nom::Err::Error(CustomError::Static("No object detected."))); } #[cfg_attr( @@ -156,9 +154,7 @@ fn detect_minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( return Ok((input, ())); } - return Err(nom::Err::Error(CustomError::MyError(MyError( - "No object detected.", - )))); + return Err(nom::Err::Error(CustomError::Static("No object detected."))); } #[cfg_attr( @@ -181,7 +177,7 @@ pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>( input, Object::PlainText ); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -204,7 +200,7 @@ fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( element!(inline_babel_call, context, input, Object::InlineBabelCall); element!(org_macro, context, input, Object::OrgMacro); element!(minimal_set_object_sans_plain_text, context, input); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -222,9 +218,7 @@ fn detect_regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( return Ok((input, ())); } - Err(nom::Err::Error(CustomError::MyError(MyError( - "No object detected.", - )))) + Err(nom::Err::Error(CustomError::Static("No object detected."))) } #[cfg_attr( @@ -242,7 +236,7 @@ pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>( input, Object::PlainText ); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -270,7 +264,7 @@ fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( element!(target, context, input, Object::Target); element!(timestamp, context, input, Object::Timestamp); element!(minimal_set_object_sans_plain_text, context, input); - Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) + Err(nom::Err::Error(CustomError::Static("No object."))) } #[cfg_attr( @@ -288,7 +282,5 @@ fn detect_table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( return Ok((input, ())); } - return Err(nom::Err::Error(CustomError::MyError(MyError( - "No object detected.", - )))); + return Err(nom::Err::Error(CustomError::Static("No object detected."))); } diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index f6fec5e..677b864 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -94,9 +94,9 @@ fn pre<'b, 'g, 'r, 's>( Some(x) if !WORD_CONSTITUENT_CHARACTERS.contains(x) => {} Some(_) => { // Not at start of line, cannot be a heading - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre character for plain link.", - )))); + ))); } }; Ok((input, ())) @@ -267,9 +267,7 @@ pub(crate) fn protocol<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "NoLinkProtocol", - )))) + Err(nom::Err::Error(CustomError::Static("NoLinkProtocol"))) } #[cfg_attr( @@ -341,9 +339,7 @@ fn impl_path_plain_end<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "No path plain end", - )))) + Err(nom::Err::Error(CustomError::Static("No path plain end"))) } #[cfg_attr( @@ -430,7 +426,7 @@ fn _path_plain_parenthesis_end<'s>( return open_parenthesis; } } - Err(nom::Err::Error(CustomError::MyError(MyError( + Err(nom::Err::Error(CustomError::Static( "No closing parenthesis", - )))) + ))) } diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 4829d56..4ffef25 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -77,9 +77,7 @@ where { return Ok((input, ())); } - return Err(nom::Err::Error(CustomError::MyError(MyError( - "No element detected.", - )))); + return Err(nom::Err::Error(CustomError::Static("No element detected."))); } #[cfg_attr( @@ -151,9 +149,9 @@ where let (final_child_start, _final_item_first_parse) = match children.pop() { Some(final_child) => final_child, None => { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Plain lists require at least one element.", - )))); + ))); } }; let final_item_context = ContextElement::ConsumeTrailingWhitespace(false); diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 6cc1915..5cb9aeb 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -117,9 +117,9 @@ impl<'x> RematchObject<'x> for PlainText<'x> { continue; } - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Target does not match.", - )))); + ))); } let source = get_consumed(input, remaining); diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 284ceb5..5cf4d02 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -38,9 +38,9 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, PropertyDrawer<'s>> { if immediate_in_section(context, "property-drawer") { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", - )))); + ))); } let ( remaining, diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 888efaf..03b27eb 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -51,9 +51,7 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>( )); } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "NoRadioLink", - )))) + Err(nom::Err::Error(CustomError::Static("NoRadioLink"))) } #[cfg_attr( @@ -97,9 +95,9 @@ pub(crate) fn rematch_target<'x, 'b, 'g, 'r, 's>( new_matches.push(new_match); } _ => { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "OnlyMinimalSetObjectsAllowed", - )))); + ))); } }; } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index d509611..244e6d8 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -482,7 +482,5 @@ fn impl_path_reg_end<'b, 'g, 'r, 's>( } } - Err(nom::Err::Error(CustomError::MyError(MyError( - "No path reg end", - )))) + Err(nom::Err::Error(CustomError::Static("No path reg end"))) } diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 1d69590..a18a787 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -231,9 +231,9 @@ fn _script_with_braces_end<'b, 'g, 'r, 's>( let current_depth = input.get_brace_depth() - starting_brace_depth; if current_depth > 0 { // Its impossible for the next character to end the subscript or superscript if we're any amount of braces deep - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid end for subscript or superscript.", - )))); + ))); } if current_depth < 0 { // This shouldn't be possible because if depth is 0 then a closing brace should end the subscript or superscript. @@ -286,7 +286,7 @@ fn _script_with_parenthesis_end<'s>( return close_parenthesis; } } - Err(nom::Err::Error(CustomError::MyError(MyError( + Err(nom::Err::Error(CustomError::Static( "No script parenthesis end.", - )))) + ))) } diff --git a/src/parser/target.rs b/src/parser/target.rs index f139b66..d91fa2f 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -41,9 +41,9 @@ pub(crate) fn target<'b, 'g, 'r, 's>( .get_preceding_character() .expect("We cannot be at the start of the file because we are inside a target."); if preceding_character.is_whitespace() { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Targets cannot end with whitespace.", - )))); + ))); } let (remaining, _) = tag(">>")(remaining)?; let (remaining, _trailing_whitespace) = diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 7f02b93..cdb1763 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -233,9 +233,9 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>( #[cfg(feature = "tracing")] let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Parent exit matcher is triggering.", - )))); + ))); } } @@ -289,9 +289,9 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>( #[cfg(feature = "tracing")] let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Parent exit matcher is triggering.", - )))); + ))); } } @@ -320,9 +320,9 @@ fn pre<'b, 'g, 'r, 's>( // If None, we are at the start of the file which is technically the beginning of a line. Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {} Some(_) => { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Not a valid pre character for text markup.", - )))); + ))); } None => unreachable!(), // None is for start of file, which should already be handled by the start_of_line matcher above. }; @@ -359,9 +359,9 @@ fn _text_markup_end<'b, 'g, 'r, 's, 'c>( contents_start_offset: usize, ) -> Res, OrgSource<'s>> { if input.get_byte_offset() == contents_start_offset { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Text markup cannot be empty", - )))); + ))); } not(preceded_by_whitespace(false))(input)?; let (remaining, _marker) = terminated( @@ -494,9 +494,9 @@ fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>( #[cfg(feature = "tracing")] let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Parent exit matcher is triggering.", - )))); + ))); } } diff --git a/src/parser/util.rs b/src/parser/util.rs index f80e1df..123adfe 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -128,9 +128,7 @@ pub(crate) fn start_of_line<'s>(input: OrgSource<'s>) -> Res, ()> if input.is_at_start_of_line() { Ok((input, ())) } else { - Err(nom::Err::Error(CustomError::MyError(MyError( - "Not at start of line", - )))) + Err(nom::Err::Error(CustomError::Static("Not at start of line"))) } } @@ -151,9 +149,9 @@ fn _preceded_by_whitespace<'s>( .map(|c| c.is_whitespace() || c == '\u{200B}') // 200B = Zero-width space .unwrap_or(allow_start_of_file) { - return Err(nom::Err::Error(CustomError::MyError(MyError( + return Err(nom::Err::Error(CustomError::Static( "Must be preceded by a whitespace character.", - )))); + ))); } Ok((input, ())) } @@ -194,9 +192,7 @@ pub(crate) fn text_until_exit<'b, 'g, 'r, 's>( #[allow(dead_code)] fn not_yet_implemented() -> Res, ()> { - Err(nom::Err::Error(CustomError::MyError(MyError( - "Not implemented yet.", - )))) + Err(nom::Err::Error(CustomError::Static("Not implemented yet."))) } #[allow(dead_code)] From e776a051ad5f5ea4a810321b89e7ca94730e725d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:13:00 -0400 Subject: [PATCH 4/6] Continue removing MyError. --- src/context/context.rs | 2 +- src/parser/document.rs | 10 +++++----- src/parser/headline.rs | 4 ++-- src/parser/regular_link.rs | 6 +----- src/parser/util.rs | 4 +--- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index 98ea66d..3a06647 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -107,7 +107,7 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> { pub(crate) fn check_exit_matcher( &'r self, i: OrgSource<'s>, - ) -> IResult, OrgSource<'s>, CustomError>> { + ) -> IResult, OrgSource<'s>, CustomError> { let mut current_class_filter = ExitClass::Gamma; for current_node in self.iter_context() { let context_element = current_node.get_data(); diff --git a/src/parser/document.rs b/src/parser/document.rs index 8e0ca88..70211b9 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -101,7 +101,7 @@ pub fn parse_file_with_settings<'g, 's, P: AsRef>( /// This will not prevent additional settings from being learned during parsing, for example when encountering a "#+TODO". #[allow(dead_code)] fn document<'s>(context: RefContext<'_, '_, '_, 's>, input: &'s str) -> Res<&'s str, Document<'s>> { - let (remaining, doc) = document_org_source(context, input.into()).map_err(convert_error)?; + let (remaining, doc) = document_org_source(context, input.into())?; Ok((Into::<&str>::into(remaining), doc)) } @@ -132,9 +132,9 @@ fn document_org_source<'b, 'g, 'r, 's>( let (_, setup_file_settings) = scan_for_in_buffer_settings(setup_file.into()).map_err(|err| { eprintln!("{}", err); - nom::Err::Error(CustomError::MyError(MyError( + nom::Err::Error(CustomError::Static( "TODO: make this take an owned string so I can dump err.to_string() into it.", - ))) + )) })?; final_settings.extend(setup_file_settings); } @@ -142,9 +142,9 @@ fn document_org_source<'b, 'g, 'r, 's>( let new_settings = apply_in_buffer_settings(final_settings, context.get_global_settings()) .map_err(|err| { eprintln!("{}", err); - nom::Err::Error(CustomError::MyError(MyError( + nom::Err::Error(CustomError::Static( "TODO: make this take an owned string so I can dump err.to_string() into it.", - ))) + )) })?; let new_context = context.with_global_settings(&new_settings); let context = &new_context; diff --git a/src/parser/headline.rs b/src/parser/headline.rs index ea98acc..ea54e98 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -285,9 +285,9 @@ fn priority_cookie(input: OrgSource<'_>) -> Res, PriorityCookie> { tag("]"), ))(input)?; let cookie = PriorityCookie::try_from(priority_character).map_err(|_| { - nom::Err::Error(CustomError::MyError(MyError( + nom::Err::Error(CustomError::Static( "Failed to cast priority cookie to number.", - ))) + )) })?; Ok((remaining, cookie)) } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 244e6d8..0097438 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -162,11 +162,7 @@ fn parse_path_reg<'b, 'g, 'r, 's>( parser_with_context!(protocol_path_reg)(context), fuzzy_path_reg, ))(replaced_input) - .map_err(|_| { - nom::Err::Error(CustomError::MyError(MyError( - "No pathreg match after replacement.", - ))) - })?; + .map_err(|_| nom::Err::Error(CustomError::Static("No pathreg match after replacement.")))?; let remaining = input.take(input.len()); let link_type = match link.link_type { LinkType::Protocol(protocol) => LinkType::Protocol(protocol.into_owned().into()), diff --git a/src/parser/util.rs b/src/parser/util.rs index 123adfe..538f2b9 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -200,9 +200,7 @@ fn not_yet_implemented() -> Res, ()> { /// Text from the current point until the next line break or end of file /// /// Useful for debugging. -fn text_until_eol<'r, 's>( - input: OrgSource<'s>, -) -> Result<&'s str, nom::Err>>> { +fn text_until_eol<'r, 's>(input: OrgSource<'s>) -> Result<&'s str, nom::Err> { let line = recognize(many_till(anychar, alt((line_ending, eof))))(input) .map(|(_remaining, line)| Into::<&str>::into(line))?; Ok(line.trim()) From 20c4a0f8f746a546098f18bdaeb93f6dfb29043a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:35:33 -0400 Subject: [PATCH 5/6] Continue removing MyError. --- src/error/error.rs | 3 ++- src/parser/citation.rs | 4 ++-- src/parser/citation_reference.rs | 4 ++-- src/parser/document.rs | 6 +++--- src/parser/entity.rs | 2 +- src/parser/greater_block.rs | 3 --- src/parser/headline.rs | 4 ++-- src/parser/in_buffer_settings.rs | 4 ++-- src/parser/keyword.rs | 15 +++++---------- src/parser/org_macro.rs | 4 ++-- src/parser/plain_link.rs | 9 ++++----- src/parser/plain_text.rs | 4 ++-- src/parser/subscript_and_superscript.rs | 4 ++-- 13 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/error/error.rs b/src/error/error.rs index b338a4f..e0d53eb 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -10,11 +10,12 @@ pub enum CustomError { Static(&'static str), IO(std::io::Error), BoxedError(Box), + Parser(ErrorKind), } impl ParseError for CustomError { fn from_error_kind(input: I, kind: ErrorKind) -> Self { - CustomError::Text(format!("{:?} {:?}", kind, input)) + CustomError::Parser(kind) } fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self { diff --git a/src/parser/citation.rs b/src/parser/citation.rs index ac8ba13..cf562fb 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -137,7 +137,7 @@ fn _global_prefix_end<'b, 'g, 'r, 's>( unreachable!("Exceeded citation global prefix bracket depth.") } if current_depth == 0 { - let close_bracket = tag::<&str, OrgSource<'_>, CustomError>>("]")(input); + let close_bracket = tag::<_, _, CustomError>("]")(input); if close_bracket.is_ok() { return close_bracket; } @@ -191,7 +191,7 @@ fn _global_suffix_end<'b, 'g, 'r, 's>( unreachable!("Exceeded citation global suffix bracket depth.") } if current_depth == 0 { - let close_bracket = tag::<&str, OrgSource<'_>, CustomError>>("]")(input); + let close_bracket = tag::<_, _, CustomError>("]")(input); if close_bracket.is_ok() { return close_bracket; } diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 9d769f7..fad3868 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -150,7 +150,7 @@ fn _key_prefix_end<'b, 'g, 'r, 's>( unreachable!("Exceeded citation key prefix bracket depth.") } if current_depth == 0 { - let close_bracket = tag::<&str, OrgSource<'_>, CustomError>>("]")(input); + let close_bracket = tag::<_, _, CustomError>("]")(input); if close_bracket.is_ok() { return close_bracket; } @@ -180,7 +180,7 @@ fn _key_suffix_end<'b, 'g, 'r, 's>( unreachable!("Exceeded citation key suffix bracket depth.") } if current_depth == 0 { - let close_bracket = tag::<&str, OrgSource<'_>, CustomError>>("]")(input); + let close_bracket = tag::<_, _, CustomError>("]")(input); if close_bracket.is_ok() { return close_bracket; } diff --git a/src/parser/document.rs b/src/parser/document.rs index 70211b9..a2122d3 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -125,7 +125,7 @@ fn document_org_source<'b, 'g, 'r, 's>( .get_global_settings() .file_access .read_file(setup_file) - .map_err(|err| nom::Err::>>::Failure(err.into())) + .map_err(|err| nom::Err::::Failure(err.into())) }) .collect::, _>>()?; for setup_file in setup_files.iter().map(String::as_str) { @@ -171,14 +171,14 @@ fn document_org_source<'b, 'g, 'r, 's>( let (remaining, mut document) = _document(&parser_context, input) .map(|(rem, out)| (Into::<&str>::into(rem), out))?; apply_post_parse_in_buffer_settings(&mut document) - .map_err(|err| nom::Err::>>::Failure(err.into()))?; + .map_err(|err| nom::Err::::Failure(err.into()))?; return Ok((remaining.into(), document)); } } // Find final in-buffer settings that do not impact parsing apply_post_parse_in_buffer_settings(&mut document) - .map_err(|err| nom::Err::>>::Failure(err.into()))?; + .map_err(|err| nom::Err::::Failure(err.into()))?; Ok((remaining.into(), document)) } diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 57ce58a..aba5fd2 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -57,7 +57,7 @@ fn name<'b, 'g, 'r, 's>( ) -> Res, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> { for entity in context.get_global_settings().entities { let result = tuple(( - tag::<_, _, CustomError<_>>(entity.name), + tag::<_, _, CustomError>(entity.name), alt(( verify(map(tag("{}"), |_| true), |_| !entity.name.ends_with(' ')), map(peek(recognize(entity_end)), |_| false), diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 4fd3d72..8fe1182 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -231,9 +231,6 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>( context_name: &'c str, ) -> Res, (&'s str, Vec>)> { if in_section(context, context_name) { - return Err(CustomError::Static( - "Cannot nest objects of the same element", - )); return Err(nom::Err::Error(CustomError::Static( "Cannot nest objects of the same element", ))); diff --git a/src/parser/headline.rs b/src/parser/headline.rs index ea54e98..7b4ffc4 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -259,7 +259,7 @@ fn heading_keyword<'b, 'g, 'r, 's>( .iter() .map(String::as_str) { - let result = tag::<_, _, CustomError<_>>(todo_keyword)(input); + let result = tag::<_, _, CustomError>(todo_keyword)(input); if let Ok((remaining, ent)) = result { return Ok((remaining, (TodoKeywordType::Todo, ent))); } @@ -269,7 +269,7 @@ fn heading_keyword<'b, 'g, 'r, 's>( .iter() .map(String::as_str) { - let result = tag::<_, _, CustomError<_>>(todo_keyword)(input); + let result = tag::<_, _, CustomError>(todo_keyword)(input); if let Ok((remaining, ent)) = result { return Ok((remaining, (TodoKeywordType::Done, ent))); } diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index 3fbc4b1..b746496 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -35,7 +35,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>( let mut remaining = input; loop { // Skip text until possible in_buffer_setting - let start_of_pound = take_until::<_, _, CustomError<_>>("#+")(remaining); + let start_of_pound = take_until::<_, _, CustomError>("#+")(remaining); let start_of_pound = if let Ok((start_of_pound, _)) = start_of_pound { start_of_pound } else { @@ -47,7 +47,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>( let (remain, maybe_kw) = match filtered_keyword(in_buffer_settings_key)(start_of_line) { Ok((remain, kw)) => (remain, Some(kw)), Err(_) => { - let end_of_line = take_until::<_, _, CustomError<_>>("\n")(start_of_pound); + let end_of_line = take_until::<_, _, CustomError>("\n")(start_of_pound); if let Ok((end_of_line, _)) = end_of_line { (end_of_line, None) } else { diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index e19c4e9..d09ed8d 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -49,10 +49,8 @@ fn _filtered_keyword<'s, F: Fn(OrgSource<'s>) -> Res, OrgSource<'s // TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references. let (remaining, (consumed_input, (_, _, parsed_key, _))) = consumed(tuple((space0, tag("#+"), key_parser, tag(":"))))(input)?; - if let Ok((remaining, _)) = tuple(( - space0::, CustomError>>, - alt((line_ending, eof)), - ))(remaining) + if let Ok((remaining, _)) = + tuple((space0::<_, CustomError>, alt((line_ending, eof))))(remaining) { return Ok(( remaining, @@ -161,10 +159,7 @@ fn plain_affiliated_key<'b, 'g, 'r, 's>( ) -> Res, OrgSource<'s>> { for keyword in context.get_global_settings().element_affiliated_keywords { let result = map( - tuple(( - tag_no_case::<_, _, CustomError<_>>(*keyword), - peek(tag(":")), - )), + tuple((tag_no_case::<_, _, CustomError>(*keyword), peek(tag(":")))), |(key, _)| key, )(input); if let Ok((remaining, ent)) = result { @@ -182,7 +177,7 @@ fn dual_affiliated_key<'b, 'g, 'r, 's>( ) -> Res, OrgSource<'s>> { for keyword in context.get_global_settings().element_dual_keywords { let result = recognize(tuple(( - tag_no_case::<_, _, CustomError<_>>(*keyword), + tag_no_case::<_, _, CustomError>(*keyword), tag("["), optval, tag("]"), @@ -221,7 +216,7 @@ fn _optval_end<'s>( unreachable!("Exceeded optval bracket depth.") } if current_depth == 0 { - let close_bracket = tag::<_, _, CustomError<_>>("]")(input); + let close_bracket = tag::<_, _, CustomError>("]")(input); if close_bracket.is_ok() { return close_bracket; } diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index d86745f..92bfbad 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -96,7 +96,7 @@ fn org_macro_arg<'b, 'g, 'r, 's>( loop { not(parser_with_context!(exit_matcher_parser)(context))(remaining)?; not(peek(tag("}}}")))(remaining)?; - if peek(tuple((space0::, CustomError<_>>, tag(")"))))(remaining).is_ok() { + if peek(tuple((space0::<_, CustomError>, tag(")"))))(remaining).is_ok() { break; } @@ -108,7 +108,7 @@ fn org_macro_arg<'b, 'g, 'r, 's>( } if next_char == '\\' { escaping = true; - if peek(tag::<_, _, CustomError<_>>(")"))(new_remaining).is_ok() { + if peek(tag::<_, _, CustomError>(")"))(new_remaining).is_ok() { // Special case for backslash at the end of a macro remaining = new_remaining; break; diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 677b864..cc4815d 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -261,7 +261,7 @@ pub(crate) fn protocol<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { for link_parameter in context.get_global_settings().link_parameters { - let result = tag_no_case::<_, _, CustomError<_>>(*link_parameter)(input); + let result = tag_no_case::<_, _, CustomError>(*link_parameter)(input); if let Ok((remaining, ent)) = result { return Ok((remaining, ent)); } @@ -324,8 +324,7 @@ fn impl_path_plain_end<'b, 'g, 'r, 's>( } if current_depth == 0 { - let close_parenthesis = - tag::<&str, OrgSource<'_>, CustomError>>(")")(remaining); + let close_parenthesis = tag::<_, _, CustomError>(")")(remaining); if close_parenthesis.is_ok() { return close_parenthesis; } @@ -415,13 +414,13 @@ fn _path_plain_parenthesis_end<'s>( unreachable!("Exceeded plain link parenthesis depth.") } if current_depth == 0 { - let close_parenthesis = tag::<&str, OrgSource<'_>, CustomError>>(")")(input); + let close_parenthesis = tag::<_, _, CustomError>(")")(input); if close_parenthesis.is_ok() { return close_parenthesis; } } if current_depth == 1 { - let open_parenthesis = tag::<&str, OrgSource<'_>, CustomError>>("(")(input); + let open_parenthesis = tag::<_, _, CustomError>("(")(input); if open_parenthesis.is_ok() { return open_parenthesis; } diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 5cb9aeb..2558182 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -91,7 +91,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> { break; } - let is_not_whitespace = is_not::<&str, &str, CustomError<_>>(" \t\r\n")(goal); + let is_not_whitespace = is_not::<_, _, CustomError>(" \t\r\n")(goal); if let Ok((new_goal, payload)) = is_not_whitespace { let (new_remaining, _) = tuple(( tag_no_case(payload), @@ -107,7 +107,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> { } let is_whitespace = recognize(many1(alt(( - recognize(one_of::<&str, &str, CustomError<_>>(" \t")), + recognize(one_of::<_, _, CustomError>(" \t")), line_ending, ))))(goal); if let Ok((new_goal, _)) = is_whitespace { diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index a18a787..ac627d1 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -38,7 +38,7 @@ pub(crate) fn detect_subscript_or_superscript<'s>(input: OrgSource<'s>) -> Res>("*")(remaining).is_ok() { + if tag::<_, _, CustomError>("*")(remaining).is_ok() { return Ok((input, ())); } let (remaining, _) = opt(one_of("+-"))(remaining)?; @@ -281,7 +281,7 @@ fn _script_with_parenthesis_end<'s>( unreachable!("Exceeded citation key suffix bracket depth.") } if current_depth == 0 { - let close_parenthesis = tag::<&str, OrgSource<'_>, CustomError>>(")")(input); + let close_parenthesis = tag::<_, _, CustomError>(")")(input); if close_parenthesis.is_ok() { return close_parenthesis; } From f59f153ee7af59bc6aaa9dab22ad7497ec8c37b6 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:39:21 -0400 Subject: [PATCH 6/6] Clean up. --- src/error/error.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/error/error.rs b/src/error/error.rs index e0d53eb..579518a 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -6,6 +6,7 @@ pub(crate) type Res = IResult; #[derive(Debug)] pub enum CustomError { + #[allow(dead_code)] Text(String), Static(&'static str), IO(std::io::Error), @@ -14,7 +15,7 @@ pub enum CustomError { } impl ParseError for CustomError { - fn from_error_kind(input: I, kind: ErrorKind) -> Self { + fn from_error_kind(_input: I, kind: ErrorKind) -> Self { CustomError::Parser(kind) }