Fixing some errors.
This commit is contained in:
parent
74a6101de7
commit
8502a8830d
@ -15,10 +15,16 @@ use nom::sequence::terminated;
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::span;
|
||||
|
||||
use super::object_parser::standard_set_object;
|
||||
use super::org_source::OrgSource;
|
||||
use super::radio_link::RematchObject;
|
||||
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
|
||||
use super::Context;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::Context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ExitClass;
|
||||
use crate::context::ExitMatcherNode;
|
||||
use crate::context::RefContext;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
@ -26,13 +32,13 @@ use crate::parser::radio_link::rematch_target;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::preceded_by_whitespace;
|
||||
use crate::parser::Bold;
|
||||
use crate::parser::Code;
|
||||
use crate::parser::Italic;
|
||||
use crate::parser::Object;
|
||||
use crate::parser::StrikeThrough;
|
||||
use crate::parser::Underline;
|
||||
use crate::parser::Verbatim;
|
||||
use crate::types::Bold;
|
||||
use crate::types::Code;
|
||||
use crate::types::Italic;
|
||||
use crate::types::Object;
|
||||
use crate::types::StrikeThrough;
|
||||
use crate::types::Underline;
|
||||
use crate::types::Verbatim;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn text_markup<'r, 's>(
|
||||
@ -154,13 +160,15 @@ pub fn code<'r, 's>(
|
||||
))
|
||||
}
|
||||
|
||||
fn text_markup_object(
|
||||
marker_symbol: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
|
||||
fn text_markup_object<'c>(
|
||||
marker_symbol: &'c str,
|
||||
) -> impl for<'b, 'r, 's> Fn(
|
||||
RefContext<'b, 'r, 's>,
|
||||
OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Vec<Object<'s>>>
|
||||
+ 'c {
|
||||
let marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_object(context, input, marker_symbol.as_str())
|
||||
}
|
||||
move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol.as_str())
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@ -173,11 +181,11 @@ fn _text_markup_object<'r, 's, 'x>(
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
}));
|
||||
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (remaining, (children, _exit_contents)) = verify(
|
||||
many_till(
|
||||
@ -205,13 +213,14 @@ fn _text_markup_object<'r, 's, 'x>(
|
||||
Ok((remaining, children))
|
||||
}
|
||||
|
||||
fn text_markup_string(
|
||||
marker_symbol: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_string(context, input, marker_symbol.as_str())
|
||||
}
|
||||
fn text_markup_string<'c>(
|
||||
marker_symbol: &'c str,
|
||||
) -> impl for<'b, 'r, 's> Fn(
|
||||
RefContext<'b, 'r, 's>,
|
||||
OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>>
|
||||
+ 'c {
|
||||
move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@ -224,11 +233,11 @@ fn _text_markup_string<'r, 's, 'x>(
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
}));
|
||||
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (remaining, contents) = recognize(verify(
|
||||
many_till(
|
||||
@ -257,7 +266,10 @@ fn _text_markup_string<'r, 's, 'x>(
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
pub fn pre<'r, 's>(
|
||||
_context: RefContext<'_, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
let preceding_character = input.get_preceding_character();
|
||||
match preceding_character {
|
||||
// If None, we are at the start of the file which is technically the beginning of a line.
|
||||
@ -274,18 +286,19 @@ pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Re
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
pub fn post<'r, 's>(
|
||||
_context: RefContext<'_, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?;
|
||||
Ok((remaining, ()))
|
||||
}
|
||||
|
||||
fn text_markup_end(
|
||||
marker_symbol: &str,
|
||||
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let marker_symbol = marker_symbol.to_owned();
|
||||
move |context: Context, input: OrgSource<'_>| {
|
||||
_text_markup_end(context, input, marker_symbol.as_str())
|
||||
}
|
||||
fn text_markup_end<'c>(
|
||||
marker_symbol: &'c str,
|
||||
) -> impl for<'r, 's> Fn(RefContext<'_, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> + 'c
|
||||
{
|
||||
move |context, input: OrgSource<'_>| _text_markup_end(context, input, marker_symbol)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@ -334,11 +347,11 @@ fn _rematch_text_markup_object<'r, 's, 'x>(
|
||||
let (remaining, open) = tag(marker_symbol)(remaining)?;
|
||||
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
|
||||
let text_markup_end_specialized = text_markup_end(open.into());
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
}));
|
||||
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &text_markup_end_specialized,
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (remaining, children) =
|
||||
// TODO: This doesn't really check the exit matcher between each object. I think it may be possible to construct an org document that parses incorrectly with the current code.
|
||||
|
@ -65,11 +65,11 @@ fn sexp<'r, 's>(
|
||||
context: RefContext<'_, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &sexp_end,
|
||||
}));
|
||||
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &sexp_end,
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (remaining, body) = recognize(verify(
|
||||
many_till(
|
||||
@ -97,11 +97,11 @@ fn active_timestamp<'r, 's>(
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("<")(input)?;
|
||||
let (remaining, _date) = date(context, remaining)?;
|
||||
let time_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
}));
|
||||
let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
});
|
||||
let time_context = context.with_additional_node(&time_context);
|
||||
let (remaining, _time) =
|
||||
opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?;
|
||||
let (remaining, _repeater) =
|
||||
@ -131,11 +131,11 @@ fn inactive_timestamp<'r, 's>(
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("[")(input)?;
|
||||
let (remaining, _date) = date(context, remaining)?;
|
||||
let time_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &inactive_time_rest_end,
|
||||
}));
|
||||
let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &inactive_time_rest_end,
|
||||
});
|
||||
let time_context = context.with_additional_node(&time_context);
|
||||
let (remaining, _time) =
|
||||
opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?;
|
||||
let (remaining, _repeater) =
|
||||
@ -187,16 +187,16 @@ fn active_time_range_timestamp<'r, 's>(
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("<")(input)?;
|
||||
let (remaining, _date) = date(context, remaining)?;
|
||||
let time_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
}));
|
||||
let first_time_context =
|
||||
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &time_range_rest_end,
|
||||
}));
|
||||
let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &active_time_rest_end,
|
||||
});
|
||||
let time_context = context.with_additional_node(&time_context);
|
||||
let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &time_range_rest_end,
|
||||
});
|
||||
let first_time_context = time_context.with_additional_node(&first_time_context);
|
||||
let (remaining, _first_time) =
|
||||
tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?;
|
||||
let (remaining, _) = tag("-")(remaining)?;
|
||||
@ -250,16 +250,16 @@ fn inactive_time_range_timestamp<'r, 's>(
|
||||
) -> Res<OrgSource<'s>, Timestamp<'s>> {
|
||||
let (remaining, _) = tag("[")(input)?;
|
||||
let (remaining, _date) = date(context, remaining)?;
|
||||
let time_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &inactive_time_rest_end,
|
||||
}));
|
||||
let first_time_context =
|
||||
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &time_range_rest_end,
|
||||
}));
|
||||
let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &inactive_time_rest_end,
|
||||
});
|
||||
let time_context = context.with_additional_node(&time_context);
|
||||
let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &time_range_rest_end,
|
||||
});
|
||||
let first_time_context = time_context.with_additional_node(&first_time_context);
|
||||
let (remaining, _first_time) =
|
||||
tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?;
|
||||
let (remaining, _) = tag("-")(remaining)?;
|
||||
@ -307,11 +307,11 @@ fn dayname<'r, 's>(
|
||||
context: RefContext<'_, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &dayname_end,
|
||||
}));
|
||||
let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
class: ExitClass::Gamma,
|
||||
exit_matcher: &dayname_end,
|
||||
});
|
||||
let parser_context = context.with_additional_node(&parser_context);
|
||||
|
||||
let (remaining, body) = recognize(verify(
|
||||
many_till(
|
||||
|
Loading…
Reference in New Issue
Block a user