Apply more suggestions.

This commit is contained in:
Tom Alexander 2023-10-16 17:03:16 -04:00
parent 4ba0e3611b
commit 2dd5246506
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 28 additions and 38 deletions

View File

@ -69,9 +69,7 @@ pub(crate) fn compare_noop<'b, 's, 'x, R, RG>(
/// Do no comparison. /// Do no comparison.
/// ///
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values. /// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
pub(crate) fn compare_identity() -> () { pub(crate) fn compare_identity() {}
()
}
/// Assert that the emacs value is always nil or absent. /// Assert that the emacs value is always nil or absent.
/// ///

View File

@ -232,8 +232,7 @@ mod tests {
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let paragraph_matcher = parser_with_context!(element(true))(&initial_context); let paragraph_matcher = parser_with_context!(element(true))(&initial_context);
let (remaining, first_paragraph) = let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph");
paragraph_matcher(input.into()).expect("Parse first paragraph");
let first_paragraph = match first_paragraph { let first_paragraph = match first_paragraph {
Element::Paragraph(paragraph) => paragraph, Element::Paragraph(paragraph) => paragraph,
_ => panic!("Should be a paragraph!"), _ => panic!("Should be a paragraph!"),
@ -255,7 +254,7 @@ mod tests {
source: "*bar* ", source: "*bar* ",
children: vec![Object::PlainText(PlainText { source: "bar" })] children: vec![Object::PlainText(PlainText { source: "bar" })]
})], })],
path: "*bar* ".into() path: "*bar* "
}) })
); );
} }

View File

@ -233,7 +233,7 @@ fn _script_with_braces_end<'b, 'g, 'r, 's>(
if current_depth > 0 { if current_depth > 0 {
// Its impossible for the next character to end the subscript or superscript if we're any amount of braces deep // 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::MyError(MyError(
"Not a valid end for subscript or superscript.".into(), "Not a valid end for subscript or superscript.",
)))); ))));
} }
if current_depth < 0 { if current_depth < 0 {
@ -288,6 +288,6 @@ fn _script_with_parenthesis_end<'s>(
} }
} }
Err(nom::Err::Error(CustomError::MyError(MyError( Err(nom::Err::Error(CustomError::MyError(MyError(
"No script parenthesis end.".into(), "No script parenthesis end.",
)))) ))))
} }

View File

@ -197,7 +197,7 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>(
let (remaining, (children, _exit_contents)) = verify( let (remaining, (children, _exit_contents)) = verify(
many_till(table_cell_set_object_matcher, exit_matcher), many_till(table_cell_set_object_matcher, exit_matcher),
|(children, exit_contents)| { |(children, exit_contents)| {
!children.is_empty() || Into::<&str>::into(exit_contents).ends_with("|") !children.is_empty() || Into::<&str>::into(exit_contents).ends_with('|')
}, },
)(remaining)?; )(remaining)?;

View File

@ -43,7 +43,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>(
.expect("We cannot be at the start of the file because we are inside a target."); .expect("We cannot be at the start of the file because we are inside a target.");
if preceding_character.is_whitespace() { if preceding_character.is_whitespace() {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Targets cannot end with whitespace.".into(), "Targets cannot end with whitespace.",
)))); ))));
} }
let (remaining, _) = tag(">>")(remaining)?; let (remaining, _) = tag(">>")(remaining)?;

View File

@ -183,13 +183,13 @@ fn code<'b, 'g, 'r, 's>(
)) ))
} }
fn text_markup_object<'c>( fn text_markup_object(
marker_symbol: &'c str, marker_symbol: &str,
) -> impl for<'b, 'g, 'r, 's> Fn( ) -> impl for<'b, 'g, 'r, 's> Fn(
RefContext<'b, 'g, 'r, 's>, RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>, OrgSource<'s>,
) -> Res<OrgSource<'s>, Vec<Object<'s>>> ) -> Res<OrgSource<'s>, Vec<Object<'s>>>
+ 'c { + '_ {
move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol) move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol)
} }
@ -235,7 +235,7 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>(
let _enter = span.enter(); let _enter = span.enter();
if exit_matcher_parser(context, remaining).is_ok() { if exit_matcher_parser(context, remaining).is_ok() {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Parent exit matcher is triggering.".into(), "Parent exit matcher is triggering.",
)))); ))));
} }
} }
@ -246,13 +246,13 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>(
Ok((remaining, children)) Ok((remaining, children))
} }
fn text_markup_string<'c>( fn text_markup_string(
marker_symbol: &'c str, marker_symbol: &str,
) -> impl for<'b, 'g, 'r, 's> Fn( ) -> impl for<'b, 'g, 'r, 's> Fn(
RefContext<'b, 'g, 'r, 's>, RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>, OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> ) -> Res<OrgSource<'s>, OrgSource<'s>>
+ 'c { + '_ {
move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol) move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol)
} }
@ -291,7 +291,7 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>(
let _enter = span.enter(); let _enter = span.enter();
if exit_matcher_parser(context, remaining).is_ok() { if exit_matcher_parser(context, remaining).is_ok() {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Parent exit matcher is triggering.".into(), "Parent exit matcher is triggering.",
)))); ))));
} }
} }
@ -322,7 +322,7 @@ fn pre<'b, 'g, 'r, 's>(
Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {} Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {}
Some(_) => { Some(_) => {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Not a valid pre character for text markup.".into(), "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. None => unreachable!(), // None is for start of file, which should already be handled by the start_of_line matcher above.
@ -343,10 +343,7 @@ fn post<'b, 'g, 'r, 's>(
Ok((remaining, ())) Ok((remaining, ()))
} }
fn text_markup_end<'c>( fn text_markup_end(marker_symbol: &str, contents_start_offset: usize) -> impl ContextMatcher + '_ {
marker_symbol: &'c str,
contents_start_offset: usize,
) -> impl ContextMatcher + 'c {
move |context, input: OrgSource<'_>| { move |context, input: OrgSource<'_>| {
_text_markup_end(context, input, marker_symbol, contents_start_offset) _text_markup_end(context, input, marker_symbol, contents_start_offset)
} }
@ -364,7 +361,7 @@ fn _text_markup_end<'b, 'g, 'r, 's, 'c>(
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
if input.get_byte_offset() == contents_start_offset { if input.get_byte_offset() == contents_start_offset {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Text markup cannot be empty".into(), "Text markup cannot be empty",
)))); ))));
} }
not(preceded_by_whitespace(false))(input)?; not(preceded_by_whitespace(false))(input)?;
@ -499,7 +496,7 @@ fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>(
let _enter = span.enter(); let _enter = span.enter();
if exit_matcher_parser(context, remaining).is_ok() { if exit_matcher_parser(context, remaining).is_ok() {
return Err(nom::Err::Error(CustomError::MyError(MyError( return Err(nom::Err::Error(CustomError::MyError(MyError(
"Parent exit matcher is triggering.".into(), "Parent exit matcher is triggering.",
)))); ))));
} }
} }

View File

@ -486,7 +486,7 @@ fn dayname_end<'b, 'g, 'r, 's>(
}))(input) }))(input)
} }
const fn time<'c>( const fn time(
allow_rest: bool, allow_rest: bool,
) -> impl for<'b, 'g, 'r, 's> Fn(RefContext<'b, 'g, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Time<'s>> ) -> impl for<'b, 'g, 'r, 's> Fn(RefContext<'b, 'g, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Time<'s>>
{ {
@ -590,6 +590,7 @@ fn time_range_rest_end<'b, 'g, 'r, 's>(
tag("-"), tag("-"),
parser_with_context!(time(true))(&parent_node), parser_with_context!(time(true))(&parent_node),
)))(input); )))(input);
#[allow(clippy::let_and_return)] // otherwise parent_node does not live long enough.
exit_contents exit_contents
} }

View File

@ -28,10 +28,7 @@ pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
/// Check if we are below a section of the given section type regardless of depth /// Check if we are below a section of the given section type regardless of depth
pub(crate) fn in_section<'b, 'g, 'r, 's, 'x>( pub(crate) fn in_section(context: RefContext<'_, '_, '_, '_>, section_name: &str) -> bool {
context: RefContext<'b, 'g, 'r, 's>,
section_name: &'x str,
) -> bool {
for thing in context.iter() { for thing in context.iter() {
match thing { match thing {
ContextElement::Context(name) if *name == section_name => return true, ContextElement::Context(name) if *name == section_name => return true,

View File

@ -120,8 +120,7 @@ pub(crate) fn coalesce_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
ret.push(c); ret.push(c);
} }
// Do nothing if preceding character was whitespace and this character also is whitespace. // Do nothing if preceding character was whitespace and this character also is whitespace.
} else { } else if c.is_ascii_whitespace() {
if c.is_ascii_whitespace() {
// Preceding character was not whitespace but this is. // Preceding character was not whitespace but this is.
sub_loop_in_whitespace = true; sub_loop_in_whitespace = true;
ret.push(' '); ret.push(' ');
@ -130,7 +129,6 @@ pub(crate) fn coalesce_whitespace_if_line_break(input: &str) -> Cow<'_, str> {
ret.push(c); ret.push(c);
} }
} }
}
if !*in_whitespace { if !*in_whitespace {
// If this line break was the start of whitespace then we need to inject a space character for it. // If this line break was the start of whitespace then we need to inject a space character for it.
ret.push(' '); ret.push(' ');