2023-04-22 02:33:10 +00:00
|
|
|
use nom::branch::alt;
|
2023-04-22 02:36:21 +00:00
|
|
|
use nom::bytes::complete::is_not;
|
2023-04-22 02:33:10 +00:00
|
|
|
use nom::bytes::complete::tag;
|
2023-04-22 02:49:00 +00:00
|
|
|
use nom::bytes::complete::tag_no_case;
|
2023-04-22 02:33:10 +00:00
|
|
|
use nom::character::complete::line_ending;
|
|
|
|
use nom::character::complete::space0;
|
2023-04-22 02:36:21 +00:00
|
|
|
use nom::character::complete::space1;
|
2023-04-22 02:33:10 +00:00
|
|
|
use nom::combinator::eof;
|
2023-04-22 02:49:00 +00:00
|
|
|
use nom::combinator::not;
|
|
|
|
use nom::combinator::peek;
|
2023-04-22 02:33:10 +00:00
|
|
|
use nom::combinator::recognize;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2023-08-23 04:30:26 +00:00
|
|
|
use super::org_source::OrgSource;
|
2023-04-22 02:33:10 +00:00
|
|
|
use super::Context;
|
|
|
|
use crate::error::Res;
|
|
|
|
use crate::parser::util::start_of_line;
|
|
|
|
use crate::parser::Keyword;
|
|
|
|
|
2023-08-11 00:04:59 +00:00
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-08-23 04:30:26 +00:00
|
|
|
pub fn keyword<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: OrgSource<'s>,
|
|
|
|
) -> Res<OrgSource<'s>, Keyword<'s>> {
|
2023-08-24 23:29:00 +00:00
|
|
|
start_of_line(input)?;
|
2023-04-22 02:36:21 +00:00
|
|
|
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
|
2023-04-22 02:33:10 +00:00
|
|
|
let (remaining, rule) = recognize(tuple((
|
|
|
|
space0,
|
2023-04-22 02:36:21 +00:00
|
|
|
tag("#+"),
|
2023-04-22 02:49:00 +00:00
|
|
|
not(peek(tag_no_case("call"))),
|
|
|
|
not(peek(tag_no_case("begin"))),
|
2023-04-22 02:36:21 +00:00
|
|
|
is_not(" \t\r\n:"),
|
|
|
|
tag(":"),
|
2023-04-22 02:44:13 +00:00
|
|
|
alt((recognize(tuple((space1, is_not("\r\n")))), space0)),
|
2023-04-22 02:33:10 +00:00
|
|
|
alt((line_ending, eof)),
|
|
|
|
)))(input)?;
|
2023-08-23 04:30:26 +00:00
|
|
|
Ok((
|
|
|
|
remaining,
|
|
|
|
Keyword {
|
|
|
|
source: rule.into(),
|
|
|
|
},
|
|
|
|
))
|
2023-04-22 02:33:10 +00:00
|
|
|
}
|