feat(elements): planning element
This commit is contained in:
parent
74fd77dba2
commit
2cba072245
10 changed files with 341 additions and 256 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use jetscii::ByteSubstring;
|
||||
use memchr::{memchr, memchr2, memrchr};
|
||||
|
||||
pub(crate) const DEFAULT_TODO_KEYWORDS: &[&str] =
|
||||
pub const DEFAULT_TODO_KEYWORDS: &[&str] =
|
||||
&["TODO", "DONE", "NEXT", "WAITING", "LATER", "CANCELLED"];
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub use self::{
|
|||
dyn_block::DynBlock,
|
||||
fn_def::FnDef,
|
||||
fn_ref::FnRef,
|
||||
headline::Headline,
|
||||
headline::{Headline, DEFAULT_TODO_KEYWORDS},
|
||||
inline_call::InlineCall,
|
||||
inline_src::InlineSrc,
|
||||
keyword::{BabelCall, Keyword},
|
||||
|
|
@ -45,6 +45,8 @@ pub use self::{
|
|||
timestamp::*,
|
||||
};
|
||||
|
||||
use indextree::NodeId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Element<'a> {
|
||||
Root,
|
||||
|
|
@ -91,6 +93,8 @@ pub enum Element<'a> {
|
|||
Document {
|
||||
begin: usize,
|
||||
end: usize,
|
||||
contents_begin: usize,
|
||||
contents_end: usize,
|
||||
},
|
||||
DynBlock {
|
||||
dyn_block: DynBlock<'a>,
|
||||
|
|
@ -157,7 +161,13 @@ pub enum Element<'a> {
|
|||
begin: usize,
|
||||
end: usize,
|
||||
},
|
||||
Planning(Planning<'a>),
|
||||
Planning {
|
||||
deadline: Option<NodeId>,
|
||||
scheduled: Option<NodeId>,
|
||||
closed: Option<NodeId>,
|
||||
begin: usize,
|
||||
end: usize,
|
||||
},
|
||||
Snippet {
|
||||
begin: usize,
|
||||
end: usize,
|
||||
|
|
|
|||
|
|
@ -6,16 +6,24 @@ use memchr::memchr;
|
|||
#[derive(Debug)]
|
||||
pub struct Planning<'a> {
|
||||
/// the date when the task should be done
|
||||
pub deadline: Option<Timestamp<'a>>,
|
||||
pub deadline: Option<&'a Timestamp<'a>>,
|
||||
/// the date when you should start working on the task
|
||||
pub scheduled: Option<Timestamp<'a>>,
|
||||
pub scheduled: Option<&'a Timestamp<'a>>,
|
||||
/// the date when the task is closed
|
||||
pub closed: Option<Timestamp<'a>>,
|
||||
pub closed: Option<&'a Timestamp<'a>>,
|
||||
}
|
||||
|
||||
impl Planning<'_> {
|
||||
#[inline]
|
||||
pub(crate) fn parse(text: &str) -> Option<(Planning<'_>, usize)> {
|
||||
pub(crate) fn parse(
|
||||
text: &str,
|
||||
) -> Option<(
|
||||
// TODO: timestamp position
|
||||
Option<(Timestamp<'_>, usize, usize)>,
|
||||
Option<(Timestamp<'_>, usize, usize)>,
|
||||
Option<(Timestamp<'_>, usize, usize)>,
|
||||
usize,
|
||||
)> {
|
||||
let (mut deadline, mut scheduled, mut closed) = (None, None, None);
|
||||
let (mut tail, off) = memchr(b'\n', text.as_bytes())
|
||||
.map(|i| (text[..i].trim(), i + 1))
|
||||
|
|
@ -28,7 +36,7 @@ impl Planning<'_> {
|
|||
($timestamp:expr) => {
|
||||
if $timestamp.is_none() {
|
||||
let (timestamp, off) = Timestamp::parse(next)?;
|
||||
$timestamp = Some(timestamp);
|
||||
$timestamp = Some((timestamp, 0, 0));
|
||||
tail = &next[off..].trim_start();
|
||||
} else {
|
||||
return None;
|
||||
|
|
@ -47,14 +55,7 @@ impl Planning<'_> {
|
|||
if deadline.is_none() && scheduled.is_none() && closed.is_none() {
|
||||
None
|
||||
} else {
|
||||
Some((
|
||||
Planning {
|
||||
deadline,
|
||||
scheduled,
|
||||
closed,
|
||||
},
|
||||
off,
|
||||
))
|
||||
Some((deadline, scheduled, closed, off))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,8 +67,9 @@ fn prase() {
|
|||
assert_eq!(
|
||||
Planning::parse("SCHEDULED: <2019-04-08 Mon>\n"),
|
||||
Some((
|
||||
Planning {
|
||||
scheduled: Some(Timestamp::Active {
|
||||
None,
|
||||
Some((
|
||||
Timestamp::Active {
|
||||
start: Datetime {
|
||||
date: "2019-04-08",
|
||||
time: None,
|
||||
|
|
@ -75,10 +77,11 @@ fn prase() {
|
|||
},
|
||||
repeater: None,
|
||||
delay: None
|
||||
}),
|
||||
closed: None,
|
||||
deadline: None,
|
||||
},
|
||||
},
|
||||
0,
|
||||
0
|
||||
)),
|
||||
None,
|
||||
"SCHEDULED: <2019-04-08 Mon>\n".len()
|
||||
))
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue