Support keywords with colons in the key and without a space between the colon and value.

This commit is contained in:
Tom Alexander 2023-09-08 22:17:10 -04:00
parent f30069efe7
commit 7545fb7e1a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -5,8 +5,8 @@ use nom::bytes::complete::tag_no_case;
use nom::bytes::complete::take_while1;
use nom::character::complete::anychar;
use nom::character::complete::line_ending;
use nom::character::complete::one_of;
use nom::character::complete::space0;
use nom::character::complete::space1;
use nom::combinator::consumed;
use nom::combinator::eof;
use nom::combinator::not;
@ -66,7 +66,7 @@ fn _filtered_keyword<'s, F: Matcher>(
}
Err(_) => {}
};
let (remaining, _ws) = space1(remaining)?;
let (remaining, _ws) = space0(remaining)?;
let (remaining, parsed_value) = recognize(many_till(
anychar,
peek(tuple((space0, alt((line_ending, eof))))),
@ -113,11 +113,15 @@ fn babel_call_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn regular_keyword_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
recognize(tuple((
not(peek(tag_no_case("call"))),
not(peek(tag_no_case("begin"))),
is_not(" \t\r\n:"),
)))(input)
not(peek(alt((tag_no_case("call"), tag_no_case("begin")))))(input)?;
recognize(many_till(
anychar,
peek(alt((
recognize(one_of(" \t\r\n")), // Give up if we hit whitespace
recognize(tuple((tag(":"), one_of(" \t\r\n")))), // Stop if we see a colon followed by whitespace
recognize(tuple((tag(":"), is_not(" \t\r\n:"), not(tag(":"))))), // Stop if we see a colon that is the last colon before whitespace. This is for keywords like "#+foo:bar:baz: lorem: ipsum" which would have the key "foo:bar:baz".
))),
))(input)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]