Add a detect_element function.
This is an optimization. When you have something like plain text which ends when it hits the next element, we only need to parse enough to detect that an element is about to occur. For elements like plain lists, this is as simple as parsing a line starting with optional whitespace and then a bullet, which avoids parsing the entire plain list tree. The benefit is most noticeable in deeply nested plain lists.
This commit is contained in:
@@ -32,6 +32,27 @@ use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::parser::util::start_of_line;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn detect_plain_list<'r, 's>(
|
||||
_context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
// TODO: Add support for plain list items that do not have content on the first line.
|
||||
if verify(
|
||||
tuple((start_of_line, space0, bullet, space1)),
|
||||
|(_start, indent, bull, _after_whitespace)| {
|
||||
Into::<&str>::into(bull) != "*" || indent.len() > 0
|
||||
},
|
||||
)(input)
|
||||
.is_ok()
|
||||
{
|
||||
return Ok((input, ()));
|
||||
}
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"No element detected.".into(),
|
||||
))));
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn plain_list<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
@@ -228,7 +249,7 @@ const fn line_indented_lte(
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _line_indented_lte<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
_context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
indent_level: usize,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
|
||||
Reference in New Issue
Block a user