Get tracing back into the element parser.

This commit is contained in:
Tom Alexander 2023-04-22 19:15:29 -04:00
parent f70babdcf4
commit 0b3f414ecf
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 74 additions and 67 deletions

View File

@ -33,71 +33,78 @@ use nom::multi::many0;
pub fn element( pub fn element(
can_be_paragraph: bool, can_be_paragraph: bool,
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, Element<'s>> { ) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, Element<'s>> {
move |context: Context, input: &str| { move |context: Context, input: &str| _element(context, input, can_be_paragraph)
let plain_list_matcher = parser_with_context!(plain_list)(context); }
let greater_block_matcher = parser_with_context!(greater_block)(context);
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context); #[tracing::instrument(ret, level = "debug")]
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context); fn _element<'r, 's>(
let comment_matcher = parser_with_context!(comment)(context); context: Context<'r, 's>,
let drawer_matcher = parser_with_context!(drawer)(context); input: &'s str,
let table_matcher = parser_with_context!(org_mode_table)(context); can_be_paragraph: bool,
let verse_block_matcher = parser_with_context!(verse_block)(context); ) -> Res<&'s str, Element<'s>> {
let comment_block_matcher = parser_with_context!(comment_block)(context); let plain_list_matcher = parser_with_context!(plain_list)(context);
let example_block_matcher = parser_with_context!(example_block)(context); let greater_block_matcher = parser_with_context!(greater_block)(context);
let export_block_matcher = parser_with_context!(export_block)(context); let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
let src_block_matcher = parser_with_context!(src_block)(context); let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
let clock_matcher = parser_with_context!(clock)(context); let comment_matcher = parser_with_context!(comment)(context);
let diary_sexp_matcher = parser_with_context!(diary_sexp)(context); let drawer_matcher = parser_with_context!(drawer)(context);
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context); let table_matcher = parser_with_context!(org_mode_table)(context);
let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context); let verse_block_matcher = parser_with_context!(verse_block)(context);
let keyword_matcher = parser_with_context!(keyword)(context); let comment_block_matcher = parser_with_context!(comment_block)(context);
let paragraph_matcher = parser_with_context!(paragraph)(context); let example_block_matcher = parser_with_context!(example_block)(context);
let latex_environment_matcher = parser_with_context!(latex_environment)(context); let export_block_matcher = parser_with_context!(export_block)(context);
let src_block_matcher = parser_with_context!(src_block)(context);
let (remaining, mut affiliated_keywords) = many0(keyword_matcher)(input)?; let clock_matcher = parser_with_context!(clock)(context);
let (remaining, mut element) = match alt(( let diary_sexp_matcher = parser_with_context!(diary_sexp)(context);
map(plain_list_matcher, Element::PlainList), let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
map(greater_block_matcher, Element::GreaterBlock), let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context);
map(dynamic_block_matcher, Element::DynamicBlock), let keyword_matcher = parser_with_context!(keyword)(context);
map(footnote_definition_matcher, Element::FootnoteDefinition), let paragraph_matcher = parser_with_context!(paragraph)(context);
map(comment_matcher, Element::Comment), let latex_environment_matcher = parser_with_context!(latex_environment)(context);
map(drawer_matcher, Element::Drawer),
map(table_matcher, Element::Table), let (remaining, mut affiliated_keywords) = many0(keyword_matcher)(input)?;
map(verse_block_matcher, Element::VerseBlock), let (remaining, mut element) = match alt((
map(comment_block_matcher, Element::CommentBlock), map(plain_list_matcher, Element::PlainList),
map(example_block_matcher, Element::ExampleBlock), map(greater_block_matcher, Element::GreaterBlock),
map(export_block_matcher, Element::ExportBlock), map(dynamic_block_matcher, Element::DynamicBlock),
map(src_block_matcher, Element::SrcBlock), map(footnote_definition_matcher, Element::FootnoteDefinition),
map(clock_matcher, Element::Clock), map(comment_matcher, Element::Comment),
map(diary_sexp_matcher, Element::DiarySexp), map(drawer_matcher, Element::Drawer),
map(fixed_width_area_matcher, Element::FixedWidthArea), map(table_matcher, Element::Table),
map(horizontal_rule_matcher, Element::HorizontalRule), map(verse_block_matcher, Element::VerseBlock),
map(latex_environment_matcher, Element::LatexEnvironment), map(comment_block_matcher, Element::CommentBlock),
))(remaining) map(example_block_matcher, Element::ExampleBlock),
{ map(export_block_matcher, Element::ExportBlock),
the_ok @ Ok(_) => the_ok, map(src_block_matcher, Element::SrcBlock),
Err(_) => { map(clock_matcher, Element::Clock),
if can_be_paragraph { map(diary_sexp_matcher, Element::DiarySexp),
match map(paragraph_matcher, Element::Paragraph)(remaining) { map(fixed_width_area_matcher, Element::FixedWidthArea),
the_ok @ Ok(_) => the_ok, map(horizontal_rule_matcher, Element::HorizontalRule),
Err(_) => { map(latex_environment_matcher, Element::LatexEnvironment),
affiliated_keywords.clear(); ))(remaining)
map(keyword_matcher, Element::Keyword)(input) {
} the_ok @ Ok(_) => the_ok,
} Err(_) => {
} else { if can_be_paragraph {
affiliated_keywords.clear(); match map(paragraph_matcher, Element::Paragraph)(remaining) {
map(keyword_matcher, Element::Keyword)(input) the_ok @ Ok(_) => the_ok,
} Err(_) => {
} affiliated_keywords.clear();
}?; map(keyword_matcher, Element::Keyword)(input)
}
let (remaining, _trailing_ws) = }
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; } else {
affiliated_keywords.clear();
let source = get_consumed(input, remaining); map(keyword_matcher, Element::Keyword)(input)
element.set_source(source); }
}
Ok((remaining, element)) }?;
}
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
element.set_source(source);
Ok((remaining, element))
} }