Implement parser for date.
This commit is contained in:
parent
70f2747291
commit
d4a3628481
@ -1,11 +1,15 @@
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
|
use nom::character::complete::digit1;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::character::complete::space1;
|
||||||
|
use nom::combinator::opt;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
@ -76,6 +80,8 @@ fn active_timestamp<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Timestamp<'s>> {
|
) -> Res<&'s str, Timestamp<'s>> {
|
||||||
|
let (remaining, _) = tag("<")(input)?;
|
||||||
|
let (remaining, _date) = date(context, remaining)?;
|
||||||
not_yet_implemented()?;
|
not_yet_implemented()?;
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@ -124,3 +130,43 @@ fn inactive_time_range_timestamp<'r, 's>(
|
|||||||
not_yet_implemented()?;
|
not_yet_implemented()?;
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn date<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
let (remaining, _year) = verify(digit1, |year: &str| year.len() == 4)(input)?;
|
||||||
|
let (remaining, _) = tag("-")(remaining)?;
|
||||||
|
let (remaining, _month) = verify(digit1, |month: &str| month.len() == 2)(remaining)?;
|
||||||
|
let (remaining, _) = tag("-")(remaining)?;
|
||||||
|
let (remaining, _day_of_month) =
|
||||||
|
verify(digit1, |day_of_month: &str| day_of_month.len() == 2)(remaining)?;
|
||||||
|
let (remaining, _dayname) =
|
||||||
|
opt(tuple((space1, parser_with_context!(dayname)(context))))(remaining)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, source))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn dayname<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
let parser_context =
|
||||||
|
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
|
class: ExitClass::Beta,
|
||||||
|
exit_matcher: &dayname_end,
|
||||||
|
}));
|
||||||
|
|
||||||
|
let (remaining, body) = recognize(verify(
|
||||||
|
many_till(
|
||||||
|
anychar,
|
||||||
|
parser_with_context!(exit_matcher_parser)(&parser_context),
|
||||||
|
),
|
||||||
|
|(body, _end_contents)| !body.is_empty(),
|
||||||
|
))(input)?;
|
||||||
|
|
||||||
|
Ok((remaining, body))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn dayname_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
recognize(verify(anychar, |c| {
|
||||||
|
c.is_whitespace() || "+-]>0123456789\n".contains(*c)
|
||||||
|
}))(input)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user