Remove unnecessary context from some util functions.
All checks were successful
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded

This commit is contained in:
Tom Alexander 2023-08-24 19:29:00 -04:00
parent e5224cda63
commit cf37bc4111
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
20 changed files with 38 additions and 55 deletions

View File

@ -24,7 +24,7 @@ pub fn clock<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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)?;

View File

@ -55,7 +55,7 @@ fn comment_line<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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("#"),

View File

@ -19,7 +19,7 @@ pub fn diary_sexp<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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)?;

View File

@ -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),

View File

@ -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>, OrgSource<'s>> {
start_of_line(context, input)?;
start_of_line(input)?;
recognize(tuple((
space0,
tag_no_case(":end:"),

View File

@ -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>, OrgSource<'s>> {
start_of_line(context, input)?;
start_of_line(input)?;
let (remaining, source) = recognize(tuple((
space0,
tag_no_case("#+end:"),

View File

@ -45,7 +45,7 @@ fn fixed_width_area_line<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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(":"),

View File

@ -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>, 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<OrgSource<'_>>| {
lines.len() >= 2
}),

View File

@ -37,7 +37,7 @@ pub fn greater_block<'r, 's>(
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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>, 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())),
))?;

View File

@ -19,7 +19,7 @@ pub fn horizontal_rule<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, HorizontalRule<'s>> {
start_of_line(context, input)?;
start_of_line(input)?;
let (remaining, rule) = recognize(tuple((
space0,
verify(many1_count(tag("-")), |dashes| *dashes >= 5),

View File

@ -22,7 +22,7 @@ pub fn keyword<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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,

View File

@ -28,7 +28,7 @@ pub fn latex_environment<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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>, 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{"#),

View File

@ -254,7 +254,7 @@ fn _lesser_block_end<'r, 's, 'x>(
input: OrgSource<'s>,
current_name_lower: &'x str,
) -> Res<OrgSource<'s>, 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>, 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_"),

View File

@ -58,9 +58,8 @@ fn paragraph_end<'r, 's>(
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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)

View File

@ -108,7 +108,7 @@ pub fn plain_list_item<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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>, 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<OrgSource<'_>>| {
lines.len() >= 2
}),
@ -200,7 +199,7 @@ fn plain_list_item_end<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
start_of_line(context, input)?;
start_of_line(input)?;
recognize(tuple((
opt(blank_line),
parser_with_context!(line_indented_lte)(context),

View File

@ -21,7 +21,7 @@ pub fn planning<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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)?;

View File

@ -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>, 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<OrgSource<'s>, 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),

View File

@ -36,7 +36,7 @@ pub fn org_mode_table<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, 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>, 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<OrgSource<'s>, 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<OrgSource<'s>, 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)?;

View File

@ -296,7 +296,7 @@ fn _text_markup_end<'r, 's, 'x>(
input: OrgSource<'s>,
marker_symbol: &'x str,
) -> Res<OrgSource<'s>, 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)),

View File

@ -63,11 +63,8 @@ pub fn blank_line(input: OrgSource<'_>) -> Res<OrgSource<'_>, 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>, OrgSource<'s>> {
start_of_line(context, input)?;
pub fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, 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<OrgSource<'s>, Option<OrgSource<'s>>> {
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<OrgSource<'s>, Option<OrgSource<'s>>> {
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<OrgSource<'s>, ()> {
pub fn start_of_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
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<OrgSource<'s>, ()> {
pub fn preceded_by_whitespace<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
let preceding_character = input.get_preceding_character();
match preceding_character {
Some('\n') | Some('\r') | Some(' ') | Some('\t') => {}