Update getting the previous character and previous line.
This can be done a lot more efficiently now that we are keeping track of this information in the wrapped input type instead of having to fetch to the original document out of the context tree.
This commit is contained in:
@@ -10,8 +10,6 @@ use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::get_current_line_before_position;
|
||||
use crate::parser::util::get_one_before;
|
||||
use crate::parser::LineBreak;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@@ -34,10 +32,7 @@ pub fn line_break<'r, 's>(
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn pre<'r, 's>(context: Context<'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
.map(|slice| slice.chars().next())
|
||||
.flatten();
|
||||
let preceding_character = input.get_preceding_character();
|
||||
match preceding_character {
|
||||
// If None, we are at the start of the file
|
||||
None | Some('\\') => {
|
||||
@@ -47,21 +42,13 @@ fn pre<'r, 's>(context: Context<'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
let current_line = get_current_line_before_position(document_root, input);
|
||||
match current_line {
|
||||
Some(line) => {
|
||||
let is_non_empty_line = Into::<&str>::into(line).chars().any(|c| !c.is_whitespace());
|
||||
if !is_non_empty_line {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre line for line break.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"No preceding line for line break.".into(),
|
||||
))));
|
||||
}
|
||||
|
||||
let current_line = input.text_since_line_break();
|
||||
let is_non_empty_line = current_line.chars().any(|c| !c.is_whitespace());
|
||||
if !is_non_empty_line {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre line for line break.".into(),
|
||||
))));
|
||||
}
|
||||
|
||||
Ok((input, ()))
|
||||
|
||||
Reference in New Issue
Block a user