From 20c4a0f8f746a546098f18bdaeb93f6dfb29043a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:35:33 -0400 Subject: [PATCH] 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 b338a4f3..e0d53eb1 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 ac8ba13f..cf562fbf 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 9d769f7a..fad38685 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 70211b95..a2122d31 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 57ce58a3..aba5fd2c 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 4fd3d721..8fe11823 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 ea54e98c..7b4ffc40 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 3fbc4b1f..b746496f 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 e19c4e9d..d09ed8d7 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 d86745fa..92bfbad7 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 677b8640..cc4815d3 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 5cb9aeb5..2558182f 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 a18a787f..ac627d14 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; }