Fixing some errors.

This commit is contained in:
Tom Alexander 2023-09-02 23:16:02 -04:00
parent 74a6101de7
commit 8502a8830d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 98 additions and 85 deletions

View File

@ -15,10 +15,16 @@ use nom::sequence::terminated;
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
use tracing::span; use tracing::span;
use super::object_parser::standard_set_object;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::radio_link::RematchObject; use super::radio_link::RematchObject;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; 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::CustomError;
use crate::error::MyError; use crate::error::MyError;
use crate::error::Res; 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::exit_matcher_parser;
use crate::parser::util::get_consumed; use crate::parser::util::get_consumed;
use crate::parser::util::preceded_by_whitespace; use crate::parser::util::preceded_by_whitespace;
use crate::parser::Bold; use crate::types::Bold;
use crate::parser::Code; use crate::types::Code;
use crate::parser::Italic; use crate::types::Italic;
use crate::parser::Object; use crate::types::Object;
use crate::parser::StrikeThrough; use crate::types::StrikeThrough;
use crate::parser::Underline; use crate::types::Underline;
use crate::parser::Verbatim; use crate::types::Verbatim;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn text_markup<'r, 's>( pub fn text_markup<'r, 's>(
@ -154,13 +160,15 @@ pub fn code<'r, 's>(
)) ))
} }
fn text_markup_object( fn text_markup_object<'c>(
marker_symbol: &str, marker_symbol: &'c str,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Vec<Object<'s>>> { ) -> 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(); let marker_symbol = marker_symbol.to_owned();
move |context: Context, input: OrgSource<'_>| { move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol.as_str())
_text_markup_object(context, input, marker_symbol.as_str())
}
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[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, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into()); let text_markup_end_specialized = text_markup_end(open.into());
let parser_context = let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &text_markup_end_specialized,
exit_matcher: &text_markup_end_specialized, });
})); let parser_context = context.with_additional_node(&parser_context);
let (remaining, (children, _exit_contents)) = verify( let (remaining, (children, _exit_contents)) = verify(
many_till( many_till(
@ -205,13 +213,14 @@ fn _text_markup_object<'r, 's, 'x>(
Ok((remaining, children)) Ok((remaining, children))
} }
fn text_markup_string( fn text_markup_string<'c>(
marker_symbol: &str, marker_symbol: &'c str,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'b, 'r, 's> Fn(
let marker_symbol = marker_symbol.to_owned(); RefContext<'b, 'r, 's>,
move |context: Context, input: OrgSource<'_>| { OrgSource<'s>,
_text_markup_string(context, input, marker_symbol.as_str()) ) -> 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"))] #[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, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into()); let text_markup_end_specialized = text_markup_end(open.into());
let parser_context = let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &text_markup_end_specialized,
exit_matcher: &text_markup_end_specialized, });
})); let parser_context = context.with_additional_node(&parser_context);
let (remaining, contents) = recognize(verify( let (remaining, contents) = recognize(verify(
many_till( many_till(
@ -257,7 +266,10 @@ fn _text_markup_string<'r, 's, 'x>(
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[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(); let preceding_character = input.get_preceding_character();
match preceding_character { match preceding_character {
// If None, we are at the start of the file which is technically the beginning of a line. // 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"))] #[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)?; let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?;
Ok((remaining, ())) Ok((remaining, ()))
} }
fn text_markup_end( fn text_markup_end<'c>(
marker_symbol: &str, marker_symbol: &'c str,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> impl for<'r, 's> Fn(RefContext<'_, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> + 'c
let marker_symbol = marker_symbol.to_owned(); {
move |context: Context, input: OrgSource<'_>| { move |context, input: OrgSource<'_>| _text_markup_end(context, input, marker_symbol)
_text_markup_end(context, input, marker_symbol.as_str())
}
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[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, open) = tag(marker_symbol)(remaining)?;
let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?;
let text_markup_end_specialized = text_markup_end(open.into()); let text_markup_end_specialized = text_markup_end(open.into());
let parser_context = let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &text_markup_end_specialized,
exit_matcher: &text_markup_end_specialized, });
})); let parser_context = context.with_additional_node(&parser_context);
let (remaining, children) = 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. // 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.

View File

@ -65,11 +65,11 @@ fn sexp<'r, 's>(
context: RefContext<'_, 'r, 's>, context: RefContext<'_, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context = let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &sexp_end,
exit_matcher: &sexp_end, });
})); let parser_context = context.with_additional_node(&parser_context);
let (remaining, body) = recognize(verify( let (remaining, body) = recognize(verify(
many_till( many_till(
@ -97,11 +97,11 @@ fn active_timestamp<'r, 's>(
) -> Res<OrgSource<'s>, Timestamp<'s>> { ) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("<")(input)?; let (remaining, _) = tag("<")(input)?;
let (remaining, _date) = date(context, remaining)?; let (remaining, _date) = date(context, remaining)?;
let time_context = let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &active_time_rest_end,
exit_matcher: &active_time_rest_end, });
})); let time_context = context.with_additional_node(&time_context);
let (remaining, _time) = let (remaining, _time) =
opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?; opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?;
let (remaining, _repeater) = let (remaining, _repeater) =
@ -131,11 +131,11 @@ fn inactive_timestamp<'r, 's>(
) -> Res<OrgSource<'s>, Timestamp<'s>> { ) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("[")(input)?; let (remaining, _) = tag("[")(input)?;
let (remaining, _date) = date(context, remaining)?; let (remaining, _date) = date(context, remaining)?;
let time_context = let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &inactive_time_rest_end,
exit_matcher: &inactive_time_rest_end, });
})); let time_context = context.with_additional_node(&time_context);
let (remaining, _time) = let (remaining, _time) =
opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?; opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?;
let (remaining, _repeater) = let (remaining, _repeater) =
@ -187,16 +187,16 @@ fn active_time_range_timestamp<'r, 's>(
) -> Res<OrgSource<'s>, Timestamp<'s>> { ) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("<")(input)?; let (remaining, _) = tag("<")(input)?;
let (remaining, _date) = date(context, remaining)?; let (remaining, _date) = date(context, remaining)?;
let time_context = let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &active_time_rest_end,
exit_matcher: &active_time_rest_end, });
})); let time_context = context.with_additional_node(&time_context);
let first_time_context = let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &time_range_rest_end,
exit_matcher: &time_range_rest_end, });
})); let first_time_context = time_context.with_additional_node(&first_time_context);
let (remaining, _first_time) = let (remaining, _first_time) =
tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?; tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?;
let (remaining, _) = tag("-")(remaining)?; let (remaining, _) = tag("-")(remaining)?;
@ -250,16 +250,16 @@ fn inactive_time_range_timestamp<'r, 's>(
) -> Res<OrgSource<'s>, Timestamp<'s>> { ) -> Res<OrgSource<'s>, Timestamp<'s>> {
let (remaining, _) = tag("[")(input)?; let (remaining, _) = tag("[")(input)?;
let (remaining, _date) = date(context, remaining)?; let (remaining, _date) = date(context, remaining)?;
let time_context = let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &inactive_time_rest_end,
exit_matcher: &inactive_time_rest_end, });
})); let time_context = context.with_additional_node(&time_context);
let first_time_context = let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &time_range_rest_end,
exit_matcher: &time_range_rest_end, });
})); let first_time_context = time_context.with_additional_node(&first_time_context);
let (remaining, _first_time) = let (remaining, _first_time) =
tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?; tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?;
let (remaining, _) = tag("-")(remaining)?; let (remaining, _) = tag("-")(remaining)?;
@ -307,11 +307,11 @@ fn dayname<'r, 's>(
context: RefContext<'_, 'r, 's>, context: RefContext<'_, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context = let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Gamma,
class: ExitClass::Gamma, exit_matcher: &dayname_end,
exit_matcher: &dayname_end, });
})); let parser_context = context.with_additional_node(&parser_context);
let (remaining, body) = recognize(verify( let (remaining, body) = recognize(verify(
many_till( many_till(