Implement the keyword parser.

This commit is contained in:
Tom Alexander 2023-04-21 22:36:21 -04:00
parent f0bab39778
commit 7139fce48d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 8 additions and 4 deletions

View File

@ -1,11 +1,11 @@
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::character::complete::line_ending; use nom::character::complete::line_ending;
use nom::character::complete::space0; use nom::character::complete::space0;
use nom::character::complete::space1;
use nom::combinator::eof; use nom::combinator::eof;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many1_count;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::Context; use super::Context;
@ -16,10 +16,14 @@ use crate::parser::Keyword;
#[tracing::instrument(ret, level = "debug")] #[tracing::instrument(ret, level = "debug")]
pub fn keyword<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Keyword<'s>> { pub fn keyword<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Keyword<'s>> {
start_of_line(context, input)?; 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(( let (remaining, rule) = recognize(tuple((
space0, space0,
verify(many1_count(tag("-")), |dashes| *dashes >= 5), tag("#+"),
space0, is_not(" \t\r\n:"),
tag(":"),
space1,
is_not("\r\n"),
alt((line_ending, eof)), alt((line_ending, eof)),
)))(input)?; )))(input)?;
Ok((remaining, Keyword { source: rule })) Ok((remaining, Keyword { source: rule }))