Allow affiliating keywords with regular keywords.

This commit is contained in:
Tom Alexander 2023-08-29 17:19:13 -04:00
parent e3d38cfbe2
commit 1bcd1895c0
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 15 additions and 6 deletions

View File

@ -7,3 +7,9 @@
#+name: cat
#+foo: dog
[[file:lorem/ipsum.png]]
#+name: cat
#+foo: dog
foo

View File

@ -87,6 +87,7 @@ fn _element<'r, 's>(
map(fixed_width_area_matcher, Element::FixedWidthArea),
map(horizontal_rule_matcher, Element::HorizontalRule),
map(latex_environment_matcher, Element::LatexEnvironment),
map(keyword_matcher, Element::Keyword),
))(remaining)
{
the_ok @ Ok(_) => the_ok,
@ -96,12 +97,12 @@ fn _element<'r, 's>(
the_ok @ Ok(_) => the_ok,
Err(_) => {
affiliated_keywords.clear();
map(keyword_matcher, Element::Keyword)(input)
map(affiliated_keyword_matcher, Element::Keyword)(input)
}
}
} else {
affiliated_keywords.clear();
map(keyword_matcher, Element::Keyword)(input)
map(affiliated_keyword_matcher, Element::Keyword)(input)
}
}
}?;

View File

@ -60,7 +60,6 @@ pub fn affiliated_keyword<'r, 's>(
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Keyword<'s>> {
start_of_line(input)?;
// org-element-dual-keywords
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
let (remaining, rule) = recognize(tuple((
@ -84,7 +83,7 @@ fn affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
alt((
recognize(tuple((dual_affiliated_key, tag("["), optval, tag("]")))),
plain_affiliated_key,
export_keyword
export_keyword,
))(input)
}
@ -148,7 +147,7 @@ fn _optval_end<'s>(
unreachable!("Exceeded optval bracket depth.")
}
if current_depth == 0 {
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
let close_bracket = tag::<_, _, CustomError<_>>("]")(input);
if close_bracket.is_ok() {
return close_bracket;
}
@ -158,5 +157,8 @@ fn _optval_end<'s>(
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn export_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
recognize(tuple((tag_no_case("attr_"), take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)))))(input)
recognize(tuple((
tag_no_case("attr_"),
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
)))(input)
}