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:
@@ -6,13 +6,13 @@ use nom::multi::many1;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::element_parser::detect_element;
|
||||
use super::lesser_element::Paragraph;
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::blank_line;
|
||||
use super::util::get_consumed;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::element_parser::element;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::object_parser::standard_set_object;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
@@ -57,7 +57,7 @@ fn paragraph_end<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let non_paragraph_element_matcher = parser_with_context!(element(false))(context);
|
||||
let non_paragraph_element_matcher = parser_with_context!(detect_element(false))(context);
|
||||
alt((
|
||||
recognize(tuple((start_of_line, many1(blank_line)))),
|
||||
recognize(non_paragraph_element_matcher),
|
||||
|
||||
Reference in New Issue
Block a user