81 lines
2.3 KiB
Rust
81 lines
2.3 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::digit1;
|
|
use nom::character::complete::line_ending;
|
|
use nom::character::complete::space0;
|
|
use nom::character::complete::space1;
|
|
use nom::combinator::eof;
|
|
use nom::combinator::recognize;
|
|
use nom::combinator::verify;
|
|
use nom::sequence::tuple;
|
|
|
|
use super::org_source::OrgSource;
|
|
use crate::context::parser_with_context;
|
|
use crate::context::RefContext;
|
|
use crate::error::Res;
|
|
use crate::parser::util::get_consumed;
|
|
use crate::parser::util::start_of_line;
|
|
use crate::types::Clock;
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
pub(crate) fn clock<'b, 'g, 'r, 's>(
|
|
context: RefContext<'b, 'g, 'r, 's>,
|
|
input: OrgSource<'s>,
|
|
) -> Res<OrgSource<'s>, Clock<'s>> {
|
|
start_of_line(input)?;
|
|
let (remaining, _leading_whitespace) = space0(input)?;
|
|
let (remaining, _clock) = tag_no_case("clock:")(remaining)?;
|
|
let (remaining, _gap_whitespace) = space1(remaining)?;
|
|
|
|
let (remaining, _timestamp_junk) = alt((
|
|
parser_with_context!(inactive_timestamp_range_duration)(context),
|
|
parser_with_context!(inactive_timestamp)(context),
|
|
))(remaining)?;
|
|
|
|
let source = get_consumed(input, remaining);
|
|
Ok((
|
|
remaining,
|
|
Clock {
|
|
source: source.into(),
|
|
},
|
|
))
|
|
}
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
fn inactive_timestamp_range_duration<'b, 'g, 'r, 's>(
|
|
_context: RefContext<'b, 'g, 'r, 's>,
|
|
input: OrgSource<'s>,
|
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
|
recognize(tuple((
|
|
tag("["),
|
|
is_not("\r\n]"),
|
|
tag("]--["),
|
|
is_not("\r\n]"),
|
|
tag("]"),
|
|
space1,
|
|
tag("=>"),
|
|
space1,
|
|
digit1,
|
|
tag(":"),
|
|
verify(digit1, |mm: &OrgSource<'_>| mm.len() == 2),
|
|
space0,
|
|
alt((line_ending, eof)),
|
|
)))(input)
|
|
}
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
fn inactive_timestamp<'b, 'g, 'r, 's>(
|
|
_context: RefContext<'b, 'g, 'r, 's>,
|
|
input: OrgSource<'s>,
|
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
|
recognize(tuple((
|
|
tag("["),
|
|
is_not("\r\n]"),
|
|
tag("]"),
|
|
space0,
|
|
alt((line_ending, eof)),
|
|
)))(input)
|
|
}
|