Merge branch 'trailing_whitespace_at_end_of_file'
This commit is contained in:
commit
9e2a323f6f
@ -0,0 +1,2 @@
|
|||||||
|
- foo
|
||||||
|
|
@ -69,6 +69,7 @@ pub fn plain_list<'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, PlainList<'s>> {
|
) -> Res<OrgSource<'s>, PlainList<'s>> {
|
||||||
let parser_context = context
|
let parser_context = context
|
||||||
.with_additional_node(ContextElement::Context("plain list"))
|
.with_additional_node(ContextElement::Context("plain list"))
|
||||||
|
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
|
||||||
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
class: ExitClass::Beta,
|
class: ExitClass::Beta,
|
||||||
exit_matcher: &plain_list_end,
|
exit_matcher: &plain_list_end,
|
||||||
@ -143,29 +144,32 @@ pub fn plain_list_item<'r, 's>(
|
|||||||
Into::<&str>::into(bull) != "*" || indent_level > 0
|
Into::<&str>::into(bull) != "*" || indent_level > 0
|
||||||
})(remaining)?;
|
})(remaining)?;
|
||||||
|
|
||||||
let maybe_contentless_item: Res<OrgSource<'_>, OrgSource<'_>> = eof(remaining);
|
let (remaining, maybe_tag) = opt(tuple((
|
||||||
|
space1,
|
||||||
|
parser_with_context!(item_tag)(context),
|
||||||
|
tag(" ::"),
|
||||||
|
)))(remaining)?;
|
||||||
|
let maybe_contentless_item: Res<OrgSource<'_>, OrgSource<'_>> =
|
||||||
|
peek(recognize(tuple((many0(blank_line), eof))))(remaining);
|
||||||
match maybe_contentless_item {
|
match maybe_contentless_item {
|
||||||
Ok((rem, _ws)) => {
|
Ok((_rem, _ws)) => {
|
||||||
let source = get_consumed(input, rem);
|
let (remaining, _trailing_ws) = opt(blank_line)(remaining)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
return Ok((
|
return Ok((
|
||||||
rem,
|
remaining,
|
||||||
PlainListItem {
|
PlainListItem {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
indentation: indent_level,
|
indentation: indent_level,
|
||||||
bullet: bull.into(),
|
bullet: bull.into(),
|
||||||
tag: Vec::new(),
|
tag: maybe_tag
|
||||||
|
.map(|(_ws, item_tag, _divider)| item_tag)
|
||||||
|
.unwrap_or(Vec::new()),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (remaining, maybe_tag) = opt(tuple((
|
|
||||||
space1,
|
|
||||||
parser_with_context!(item_tag)(context),
|
|
||||||
tag(" ::"),
|
|
||||||
)))(remaining)?;
|
|
||||||
let (remaining, _ws) = item_tag_post_gap(context, remaining)?;
|
let (remaining, _ws) = item_tag_post_gap(context, remaining)?;
|
||||||
let exit_matcher = plain_list_item_end(indent_level);
|
let exit_matcher = plain_list_item_end(indent_level);
|
||||||
let parser_context = context
|
let parser_context = context
|
||||||
@ -175,14 +179,24 @@ pub fn plain_list_item<'r, 's>(
|
|||||||
exit_matcher: &exit_matcher,
|
exit_matcher: &exit_matcher,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let (remaining, (children, _exit_contents)) = many_till(
|
let (mut remaining, (mut children, _exit_contents)) = many_till(
|
||||||
parser_with_context!(element(true))(&parser_context),
|
include_input(parser_with_context!(element(true))(&parser_context)),
|
||||||
alt((
|
|
||||||
peek(recognize(tuple((start_of_line, many0(blank_line), eof)))),
|
|
||||||
parser_with_context!(exit_matcher_parser)(&parser_context),
|
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||||
)),
|
|
||||||
)(remaining)?;
|
)(remaining)?;
|
||||||
|
|
||||||
|
if !children.is_empty() && !context.should_consume_trailing_whitespace() {
|
||||||
|
let final_item_context =
|
||||||
|
parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false));
|
||||||
|
let (final_child_start, _original_final_child) = children
|
||||||
|
.pop()
|
||||||
|
.expect("if-statement already checked that children was non-empty.");
|
||||||
|
let (remain, reparsed_final_element) = include_input(parser_with_context!(element(true))(
|
||||||
|
&final_item_context,
|
||||||
|
))(final_child_start)?;
|
||||||
|
remaining = remain;
|
||||||
|
children.push(reparsed_final_element);
|
||||||
|
}
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, _trailing_ws) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
@ -196,11 +210,23 @@ pub fn plain_list_item<'r, 's>(
|
|||||||
tag: maybe_tag
|
tag: maybe_tag
|
||||||
.map(|(_ws, item_tag, _divider)| item_tag)
|
.map(|(_ws, item_tag, _divider)| item_tag)
|
||||||
.unwrap_or(Vec::new()),
|
.unwrap_or(Vec::new()),
|
||||||
children,
|
children: children.into_iter().map(|(_start, item)| item).collect(),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn include_input<'s, F, O>(
|
||||||
|
mut inner: F,
|
||||||
|
) -> impl FnMut(OrgSource<'s>) -> Res<OrgSource<'s>, (OrgSource<'s>, O)>
|
||||||
|
where
|
||||||
|
F: FnMut(OrgSource<'s>) -> Res<OrgSource<'s>, O>,
|
||||||
|
{
|
||||||
|
move |input: OrgSource<'_>| {
|
||||||
|
let (remaining, output) = inner(input)?;
|
||||||
|
Ok((remaining, (input, output)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn bullet<'s>(i: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn bullet<'s>(i: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
alt((
|
alt((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user