Skip to content

Instantly share code, notes, and snippets.

@rschulman
Created September 24, 2017 17:31
Show Gist options
  • Save rschulman/ac8a23c146634ccea725647e00e495fd to your computer and use it in GitHub Desktop.
Save rschulman/ac8a23c146634ccea725647e00e495fd to your computer and use it in GitHub Desktop.
#[derive(Debug, PartialEq)]
pub struct TodoCmd {
pub body: String,
pub deadline: Option<String>,
pub scheduled: Option<String>
}
named!(todo<&str, &str>, tag_no_case_s!("TODO "));
named!(todo_text<&str, &str>, alt_complete!(take_until_s!(" DEADLINE") | take_until_s!(" SCHEDULED") | rest_s));
named!(deadline<&str, &str>, do_parse!(
t: tag_no_case_s!(" DEADLINE ") >>
d: alt_complete!(take_until_s!(" SCHEDULED") | rest_s) >>
(d)
));
named!(scheduled<&str, &str>, do_parse!(
t: tag_no_case_s!(" SCHEDULED ") >>
d: alt_complete!(take_until_s!(" DEADLINE") | rest_s) >>
(d)
));
named!(pub command<&str, Command>, do_parse!(
todo >>
c: todo_text >>
d: opt!(deadline) >>
s: opt!(scheduled) >>
(Command::Todo(TodoCmd {
body: c.to_string(),
deadline: match d {
Some(deadline) => Some(deadline.to_string()),
None => None
},
scheduled: match s {
Some(scheduled) => Some(scheduled.to_string()),
None => None
},
}))
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment