diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 36c84a7..035c3e7 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -24,7 +24,7 @@ pub fn clock<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, Clock<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _clock) = tag_no_case("clock:")(remaining)?; let (remaining, _gap_whitespace) = space1(remaining)?; diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 8162877..1144c4d 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -55,7 +55,7 @@ fn comment_line<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _indent) = space0(input)?; let (remaining, (_hash, _leading_whitespace_and_content, _line_ending)) = tuple(( tag("#"), diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 869311e..5b3ec36 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -19,7 +19,7 @@ pub fn diary_sexp<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _clock) = tag("%%")(remaining)?; let (remaining, _gap_whitespace) = space0(remaining)?; diff --git a/src/parser/document.rs b/src/parser/document.rs index 29dd89f..957fff2 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -300,10 +300,9 @@ fn headline<'r, 's>( exit_matcher: &headline_end, })); let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context); - let start_of_line_matcher = parser_with_context!(start_of_line)(&parser_context); let (remaining, (_sol, star_count, ws, title, _line_ending)) = tuple(( - start_of_line_matcher, + start_of_line, many1_count(tag("*")), space1, many1(standard_set_object_matcher), diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 4e6a842..fe1de33 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -41,7 +41,7 @@ pub fn drawer<'r, 's>( "Cannot nest objects of the same element".into(), )))); } - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_open_colon, drawer_name, _close_colon, _new_line)) = tuple(( tag(":"), @@ -102,7 +102,7 @@ fn drawer_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; recognize(tuple(( space0, tag_no_case(":end:"), diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 30739ff..69f4cca 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -42,7 +42,7 @@ pub fn dynamic_block<'r, 's>( "Cannot nest objects of the same element".into(), )))); } - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, name, parameters, _ws)) = tuple(( recognize(tuple((tag_no_case("#+begin:"), space1))), @@ -110,7 +110,7 @@ fn dynamic_block_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, source) = recognize(tuple(( space0, tag_no_case("#+end:"), diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 068556d..1083928 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -45,7 +45,7 @@ fn fixed_width_area_line<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _indent) = space0(input)?; let (remaining, (_hash, _leading_whitespace_and_content, _line_ending)) = tuple(( tag(":"), diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 91eceb2..6b64314 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -39,7 +39,7 @@ pub fn footnote_definition<'r, 's>( "Cannot nest objects of the same element".into(), )))); } - start_of_line(context, input)?; + start_of_line(input)?; // Cannot be indented. let (remaining, (_lead_in, lbl, _lead_out, _ws)) = tuple((tag_no_case("[fn:"), label, tag("]"), space0))(input)?; @@ -80,7 +80,6 @@ fn footnote_definition_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let start_of_line_matcher = parser_with_context!(start_of_line)(context); let allow_nesting_context = context.with_additional_node(ContextElement::Context("allow nesting footnotes")); let footnote_definition_matcher = parser_with_context!(footnote_definition)( @@ -98,7 +97,7 @@ fn footnote_definition_end<'r, 's>( footnote_definition_matcher, ))), recognize(tuple(( - start_of_line_matcher, + start_of_line, verify(many1(blank_line), |lines: &Vec>| { lines.len() >= 2 }), diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 62c042c..fa1ca69 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -37,7 +37,7 @@ pub fn greater_block<'r, 's>( input: OrgSource<'s>, ) -> Res, GreaterBlock<'s>> { // TODO: Do I need to differentiate between different greater block types. - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, name)) = tuple(( tag_no_case("#+begin_"), @@ -125,7 +125,7 @@ fn greater_block_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let current_name: &str = get_context_greater_block_name(context).ok_or(nom::Err::Error( CustomError::MyError(MyError("Not inside a greater block".into())), ))?; diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index 88aa468..ad46eff 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -19,7 +19,7 @@ pub fn horizontal_rule<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, HorizontalRule<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, rule) = recognize(tuple(( space0, verify(many1_count(tag("-")), |dashes| *dashes >= 5), diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 8114660..a375a9c 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -22,7 +22,7 @@ pub fn keyword<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; // TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references. let (remaining, rule) = recognize(tuple(( space0, diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 84195c7..3aff4b1 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -28,7 +28,7 @@ pub fn latex_environment<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, LatexEnvironment<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_opening, name, _open_close_brace, _ws, _line_ending)) = tuple(( tag_no_case(r#"\begin{"#), @@ -101,7 +101,7 @@ fn _latex_environment_end<'r, 's, 'x>( input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, _name, _close_brace, _ws, _line_ending)) = tuple(( tag_no_case(r#"\end{"#), diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 8725def..64bb352 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -254,7 +254,7 @@ fn _lesser_block_end<'r, 's, 'x>( input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, _name, _ws)) = tuple(( tag_no_case("#+end_"), @@ -280,7 +280,7 @@ fn _lesser_block_begin<'r, 's, 'x>( input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, name)) = tuple(( tag_no_case("#+begin_"), diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 8f91e12..9591706 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -58,9 +58,8 @@ fn paragraph_end<'r, 's>( input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let non_paragraph_element_matcher = parser_with_context!(element(false))(context); - let start_of_line_matcher = parser_with_context!(start_of_line)(&context); alt(( - recognize(tuple((start_of_line_matcher, many1(blank_line)))), + recognize(tuple((start_of_line, many1(blank_line)))), recognize(non_paragraph_element_matcher), eof, ))(input) diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 810784e..f301b41 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -108,7 +108,7 @@ pub fn plain_list_item<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, PlainListItem<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, leading_whitespace) = space0(input)?; // It is fine that we get the indent level using the number of bytes rather than the number of characters because nom's space0 only matches space and tab (0x20 and 0x09) let indent_level = leading_whitespace.len(); @@ -186,9 +186,8 @@ fn plain_list_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let start_of_line_matcher = parser_with_context!(start_of_line)(context); recognize(tuple(( - start_of_line_matcher, + start_of_line, verify(many1(blank_line), |lines: &Vec>| { lines.len() >= 2 }), @@ -200,7 +199,7 @@ fn plain_list_item_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; recognize(tuple(( opt(blank_line), parser_with_context!(line_indented_lte)(context), diff --git a/src/parser/planning.rs b/src/parser/planning.rs index bbaed9c..51069ac 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -21,7 +21,7 @@ pub fn planning<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, Planning<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _planning_parameters) = separated_list1(space1, planning_parameter)(remaining)?; let (remaining, _trailing_ws) = tuple((space0, alt((line_ending, eof))))(remaining)?; diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 3e78ecf..02be168 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -44,7 +44,7 @@ pub fn property_drawer<'r, 's>( remaining, (_start_of_line, _leading_whitespace, _open_tag, _trailing_whitespace, _line_ending), ) = tuple(( - parser_with_context!(start_of_line)(context), + start_of_line, space0, tag_no_case(":PROPERTIES:"), space0, @@ -84,7 +84,7 @@ fn property_drawer_end<'r, 's>( input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( - parser_with_context!(start_of_line)(context), + start_of_line, space0, tag_no_case(":end:"), space0, @@ -99,7 +99,7 @@ fn node_property<'r, 's>( ) -> Res, NodeProperty<'s>> { let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) = tuple(( - parser_with_context!(start_of_line)(context), + start_of_line, space0, tag(":"), parser_with_context!(node_property_name)(context), diff --git a/src/parser/table.rs b/src/parser/table.rs index 01029d4..465bf48 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -36,7 +36,7 @@ pub fn org_mode_table<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, Table<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; peek(tuple((space0, tag("|"))))(input)?; let parser_context = context @@ -70,7 +70,7 @@ fn table_end<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; recognize(tuple((space0, not(tag("|")))))(input) } @@ -90,7 +90,7 @@ pub fn org_mode_table_row_rule<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _) = tuple((space0, tag("|-"), is_not("\r\n"), line_ending))(input)?; let source = get_consumed(input, remaining); Ok(( @@ -107,7 +107,7 @@ pub fn org_mode_table_row_regular<'r, 's>( context: Context<'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { - start_of_line(context, input)?; + start_of_line(input)?; let (remaining, _) = tuple((space0, tag("|")))(input)?; let (remaining, children) = many1(parser_with_context!(org_mode_table_cell)(context))(remaining)?; diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 3dd98c7..7cb5bf7 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -296,7 +296,7 @@ fn _text_markup_end<'r, 's, 'x>( input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, OrgSource<'s>> { - not(parser_with_context!(preceded_by_whitespace)(context))(input)?; + not(preceded_by_whitespace)(input)?; let (remaining, _marker) = terminated( tag(marker_symbol), peek(parser_with_context!(post)(context)), diff --git a/src/parser/util.rs b/src/parser/util.rs index 7340abb..12f3f25 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -63,11 +63,8 @@ pub fn blank_line(input: OrgSource<'_>) -> Res, OrgSource<'_>> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn element_trailing_whitespace<'r, 's>( - context: Context<'r, 's>, - input: OrgSource<'s>, -) -> Res, OrgSource<'s>> { - start_of_line(context, input)?; +pub fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + start_of_line(input)?; alt((eof, recognize(many0(blank_line))))(input) } @@ -78,9 +75,7 @@ pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( ) -> Res, Option>> { if context.should_consume_trailing_whitespace() && exit_matcher_parser(context, input).is_err() { - Ok(opt(parser_with_context!(element_trailing_whitespace)( - context, - ))(input)?) + Ok(opt(element_trailing_whitespace)(input)?) } else { Ok((input, None)) } @@ -92,9 +87,7 @@ pub fn maybe_consume_trailing_whitespace<'r, 's>( input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() { - Ok(opt(parser_with_context!(element_trailing_whitespace)( - context, - ))(input)?) + Ok(opt(element_trailing_whitespace)(input)?) } else { Ok((input, None)) } @@ -102,10 +95,7 @@ pub fn maybe_consume_trailing_whitespace<'r, 's>( /// Check that we are at the start of a line #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn start_of_line<'r, 's>( - context: Context<'r, 's>, - input: OrgSource<'s>, -) -> Res, ()> { +pub fn start_of_line<'s>(input: OrgSource<'s>) -> Res, ()> { if input.is_at_start_of_line() { Ok((input, ())) } else { @@ -117,10 +107,7 @@ pub fn start_of_line<'r, 's>( /// Check that we are at the start of a line #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn preceded_by_whitespace<'r, 's>( - context: Context<'r, 's>, - input: OrgSource<'s>, -) -> Res, ()> { +pub fn preceded_by_whitespace<'s>(input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { Some('\n') | Some('\r') | Some(' ') | Some('\t') => {}