Create a template for new element functions that will take in the affiliated keywords instead of re-parsing them multiple times.

This commit is contained in:
Tom Alexander 2023-10-12 15:47:06 -04:00
parent 176e37874e
commit a6f36ba679
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 29 additions and 4 deletions

View File

@ -25,12 +25,15 @@ use crate::types::AffiliatedKeywordValue;
use crate::types::AffiliatedKeywords;
use crate::types::Keyword;
pub(crate) fn parse_affiliated_keywords<'g, 's>(
pub(crate) fn parse_affiliated_keywords<'g, 's, AK>(
global_settings: &'g GlobalSettings<'g, 's>,
input: Vec<Keyword<'s>>,
) -> AffiliatedKeywords<'s> {
input: AK,
) -> AffiliatedKeywords<'s>
where
AK: IntoIterator<Item = Keyword<'s>>,
{
let mut ret = BTreeMap::new();
for kw in input.into_iter() {
for kw in input {
let translated_name = translate_name(global_settings, kw.key);
if is_single_string_keyword(global_settings, translated_name.as_str()) {
ret.insert(

View File

@ -2,6 +2,7 @@ use nom::branch::alt;
use nom::combinator::map;
use nom::combinator::opt;
use nom::combinator::peek;
use nom::multi::many0;
use nom::sequence::tuple;
#[cfg(feature = "tracing")]
use tracing::span;
@ -59,6 +60,8 @@ fn _element<'b, 'g, 'r, 's>(
input: OrgSource<'s>,
can_be_paragraph: bool,
) -> Res<OrgSource<'s>, Element<'s>> {
let (post_affiliated_keywords_input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
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);

1
src/parser/macros.rs Normal file
View File

@ -0,0 +1 @@

View File

@ -27,6 +27,7 @@ mod latex_environment;
mod latex_fragment;
mod lesser_block;
mod line_break;
mod macros;
mod object_parser;
mod org_macro;
mod org_source;

View File

@ -43,6 +43,7 @@ use crate::parser::util::org_space;
use crate::parser::util::start_of_line;
use crate::types::CheckboxType;
use crate::types::IndentationLevel;
use crate::types::Keyword;
use crate::types::Object;
use crate::types::PlainList;
use crate::types::PlainListItem;
@ -79,6 +80,22 @@ pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>(
))));
}
#[cfg_attr(
feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context))
)]
pub(crate) fn new_plain_list<'b, 'g, 'r, 's, AK>(
affiliated_keywords: AK,
remaining: OrgSource<'s>,
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, PlainList<'s>>
where
AK: Iterator<Item = Keyword<'s>>,
{
todo!()
}
#[cfg_attr(
feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context))