Code structure for keyword.

This commit is contained in:
Tom Alexander
2023-04-21 22:33:10 -04:00
parent 96d9158602
commit f0bab39778
7 changed files with 73 additions and 0 deletions

26
src/parser/keyword.rs Normal file
View File

@@ -0,0 +1,26 @@
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::character::complete::space0;
use nom::combinator::eof;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many1_count;
use nom::sequence::tuple;
use super::Context;
use crate::error::Res;
use crate::parser::util::start_of_line;
use crate::parser::Keyword;
#[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)?;
let (remaining, rule) = recognize(tuple((
space0,
verify(many1_count(tag("-")), |dashes| *dashes >= 5),
space0,
alt((line_ending, eof)),
)))(input)?;
Ok((remaining, Keyword { source: rule }))
}