35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use nom::branch::alt;
|
|
use nom::bytes::complete::is_not;
|
|
use nom::bytes::complete::tag;
|
|
use nom::bytes::complete::tag_no_case;
|
|
use nom::character::complete::line_ending;
|
|
use nom::character::complete::space0;
|
|
use nom::character::complete::space1;
|
|
use nom::combinator::eof;
|
|
use nom::combinator::not;
|
|
use nom::combinator::peek;
|
|
use nom::combinator::recognize;
|
|
use nom::sequence::tuple;
|
|
|
|
use super::Context;
|
|
use crate::error::Res;
|
|
use crate::parser::util::start_of_line;
|
|
use crate::parser::Keyword;
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
pub fn keyword<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Keyword<'s>> {
|
|
start_of_line(context, input)?;
|
|
// 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((
|
|
space0,
|
|
tag("#+"),
|
|
not(peek(tag_no_case("call"))),
|
|
not(peek(tag_no_case("begin"))),
|
|
is_not(" \t\r\n:"),
|
|
tag(":"),
|
|
alt((recognize(tuple((space1, is_not("\r\n")))), space0)),
|
|
alt((line_ending, eof)),
|
|
)))(input)?;
|
|
Ok((remaining, Keyword { source: rule }))
|
|
}
|