Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -4,6 +4,7 @@ use nom::character::complete::one_of;
|
||||
use nom::combinator::recognize;
|
||||
use nom::multi::many0;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::Context;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
@@ -14,17 +15,25 @@ use crate::parser::util::get_one_before;
|
||||
use crate::parser::LineBreak;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn line_break<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, LineBreak<'s>> {
|
||||
pub fn line_break<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, LineBreak<'s>> {
|
||||
let (remaining, _) = pre(context, input)?;
|
||||
let (remaining, _) = tag(r#"\\"#)(remaining)?;
|
||||
let (remaining, _) = recognize(many0(one_of(" \t")))(remaining)?;
|
||||
let (remaining, _) = line_ending(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, LineBreak { source }))
|
||||
Ok((
|
||||
remaining,
|
||||
LineBreak {
|
||||
source: source.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
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())
|
||||
@@ -33,7 +42,7 @@ fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
// If None, we are at the start of the file
|
||||
None | Some('\\') => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not a valid pre character for line break.",
|
||||
"Not a valid pre character for line break.".into(),
|
||||
))));
|
||||
}
|
||||
_ => {}
|
||||
@@ -41,16 +50,16 @@ fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
let current_line = get_current_line_before_position(document_root, input);
|
||||
match current_line {
|
||||
Some(line) => {
|
||||
let is_non_empty_line = line.chars().any(|c| !c.is_whitespace());
|
||||
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.",
|
||||
"Not a valid pre line for line break.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"No preceding line for line break.",
|
||||
"No preceding line for line break.".into(),
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user