Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -11,6 +11,7 @@ use nom::combinator::verify;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
@@ -34,8 +35,8 @@ use crate::parser::util::text_until_exit;
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn verse_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, VerseBlock<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, VerseBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("verse")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
@@ -58,7 +59,9 @@ pub fn verse_block<'r, 's>(
|
||||
let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {
|
||||
Ok((remaining, (whitespace, (_children, _exit_contents)))) => (
|
||||
remaining,
|
||||
vec![Object::PlainText(PlainText { source: whitespace })],
|
||||
vec![Object::PlainText(PlainText {
|
||||
source: whitespace.into(),
|
||||
})],
|
||||
),
|
||||
Err(_) => {
|
||||
let (remaining, (children, _exit_contents)) =
|
||||
@@ -72,9 +75,9 @@ pub fn verse_block<'r, 's>(
|
||||
Ok((
|
||||
remaining,
|
||||
VerseBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
source: source.into(),
|
||||
name: name.into(),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
children,
|
||||
},
|
||||
))
|
||||
@@ -83,8 +86,8 @@ pub fn verse_block<'r, 's>(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn comment_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, CommentBlock<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, CommentBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("comment")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
@@ -108,10 +111,10 @@ pub fn comment_block<'r, 's>(
|
||||
Ok((
|
||||
remaining,
|
||||
CommentBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
source: source.into(),
|
||||
name: name.into(),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -119,8 +122,8 @@ pub fn comment_block<'r, 's>(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn example_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, ExampleBlock<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ExampleBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("example")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = line_ending(remaining)?;
|
||||
@@ -144,10 +147,10 @@ pub fn example_block<'r, 's>(
|
||||
Ok((
|
||||
remaining,
|
||||
ExampleBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
source: source.into(),
|
||||
name: source.into(),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -155,8 +158,8 @@ pub fn example_block<'r, 's>(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn export_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, ExportBlock<'s>> {
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ExportBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("export")(context, input)?;
|
||||
// https://orgmode.org/worg/org-syntax.html#Blocks claims that export blocks must have a single word for data but testing shows no data and multi-word data still parses as an export block.
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
@@ -181,16 +184,19 @@ pub fn export_block<'r, 's>(
|
||||
Ok((
|
||||
remaining,
|
||||
ExportBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
source: source.into(),
|
||||
name: name.into(),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn src_block<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, SrcBlock<'s>> {
|
||||
pub fn src_block<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, SrcBlock<'s>> {
|
||||
let (remaining, name) = lesser_block_begin("src")(context, input)?;
|
||||
// https://orgmode.org/worg/org-syntax.html#Blocks claims that data is mandatory and must follow the LANGUAGE SWITCHES ARGUMENTS pattern but testing has shown that no data and incorrect data here will still parse to a src block.
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
@@ -215,29 +221,29 @@ pub fn src_block<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
||||
Ok((
|
||||
remaining,
|
||||
SrcBlock {
|
||||
source,
|
||||
name,
|
||||
data: parameters,
|
||||
contents,
|
||||
source: source.into(),
|
||||
name: name.into(),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn name<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
is_not(" \t\r\n")(input)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn data<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn data<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
is_not("\r\n")(input)
|
||||
}
|
||||
|
||||
fn lesser_block_end(
|
||||
current_name: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str> {
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let current_name_lower = current_name.to_lowercase();
|
||||
move |context: Context, input: &str| {
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_lesser_block_end(context, input, current_name_lower.as_str())
|
||||
}
|
||||
}
|
||||
@@ -245,9 +251,9 @@ fn lesser_block_end(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _lesser_block_end<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
current_name_lower: &'x str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, _name, _ws)) = tuple((
|
||||
@@ -261,9 +267,9 @@ fn _lesser_block_end<'r, 's, 'x>(
|
||||
|
||||
fn lesser_block_begin(
|
||||
current_name: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str> {
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let current_name_lower = current_name.to_lowercase();
|
||||
move |context: Context, input: &str| {
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_lesser_block_begin(context, input, current_name_lower.as_str())
|
||||
}
|
||||
}
|
||||
@@ -271,15 +277,15 @@ fn lesser_block_begin(
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn _lesser_block_begin<'r, 's, 'x>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
input: OrgSource<'s>,
|
||||
current_name_lower: &'x str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _leading_whitespace) = space0(input)?;
|
||||
let (remaining, (_begin, name)) = tuple((
|
||||
tag_no_case("#+begin_"),
|
||||
verify(name, |name: &str| {
|
||||
name.to_lowercase().as_str() == current_name_lower
|
||||
verify(name, |name: &OrgSource<'_>| {
|
||||
Into::<&str>::into(name).to_lowercase().as_str() == current_name_lower
|
||||
}),
|
||||
))(remaining)?;
|
||||
Ok((remaining, name))
|
||||
|
||||
Reference in New Issue
Block a user