remove more taskwarrior compatibility stuff

This commit is contained in:
Dustin J. Mitchell 2020-11-22 00:51:41 -05:00
parent b3a0fe9f20
commit f45292d049
7 changed files with 0 additions and 3486 deletions

View file

@ -4,7 +4,4 @@ use failure::Fail;
pub enum Error {
#[fail(display = "Task Database Error: {}", _0)]
DBError(String),
#[fail(display = "TDB2 Error: {}", _0)]
TDB2Error(String),
}

View file

@ -12,7 +12,6 @@ mod server;
mod task;
mod taskdb;
pub mod taskstorage;
mod util;
pub use operation::Operation;
pub use replica::Replica;

View file

@ -1,39 +0,0 @@
//! A re-implementation of the "Datetime" parsing utility from the Taskwarrior
//! source.
// TODO: this module is not yet implemented
pub(crate) struct DateTime {}
impl DateTime {
/// Parse a datestamp from a prefix of input and return the number of bytes consumed in the
/// input
pub(crate) fn parse<S: AsRef<str>>(
input: S,
format: &'static str,
) -> Option<(DateTime, usize)> {
let input = input.as_ref();
let mut len = input.len();
// try parsing the whole string and repeatedly drop suffixes until a match
while len > 0 {
if let Some(str) = input.get(..len) {
match str {
"2015" => return Some((DateTime {}, len)),
"2015-" => return Some((DateTime {}, len)),
"9th" => return Some((DateTime {}, len)),
"10th" => return Some((DateTime {}, len)),
"2015-W01" => return Some((DateTime {}, len)),
"2015-02-17" => return Some((DateTime {}, len)),
"2013-11-29T22:58:00Z" => return Some((DateTime {}, len)),
"315532800" => return Some((DateTime {}, len)),
"20131129T225800Z" => return Some((DateTime {}, len)),
"today" => return Some((DateTime {}, len)),
_ => (),
}
}
len -= 1;
}
None
}
}

View file

@ -1,44 +0,0 @@
//! A re-implementation of the "Duration" parsing utility from the Taskwarrior
//! source.
// TODO: this module is not yet implemented
pub(crate) struct Duration {}
impl Duration {
/// Parse a duration from a prefix of input and return the number of bytes consumed in the
/// input
pub(crate) fn parse<S: AsRef<str>>(
input: S,
format: &'static str,
) -> Option<(Duration, usize)> {
let input = input.as_ref();
let mut len = input.len();
// try parsing the whole string and repeatedly drop suffixes until a match
while len > 0 {
if let Some(str) = input.get(..len) {
match str {
"1w" => return Some((Duration {}, len)),
"4w" => return Some((Duration {}, len)),
"4weeks" => return Some((Duration {}, len)),
"5mo" => return Some((Duration {}, len)),
"6 years" => return Some((Duration {}, len)),
"3 days" => return Some((Duration {}, len)),
"1minute" => return Some((Duration {}, len)),
"2hour" => return Some((Duration {}, len)),
"1s" => return Some((Duration {}, len)),
"1second" => return Some((Duration {}, len)),
"PT23H" => return Some((Duration {}, len)),
"PT1H" => return Some((Duration {}, len)),
"P1Y" => return Some((Duration {}, len)),
"P1Y1M1DT1H1M1S" => return Some((Duration {}, len)),
"year" => return Some((Duration {}, len)),
_ => (),
}
}
len -= 1;
}
None
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +0,0 @@
pub(crate) mod datetime;
pub(crate) mod duration;
pub(crate) mod lexer;
pub(crate) mod pig;

View file

@ -1,201 +0,0 @@
//! A minimal implementation of the "Pig" parsing utility from the Taskwarrior
//! source. This is just enough to parse FF4 lines.
use failure::Fallible;
pub(crate) struct Pig<'a> {
input: &'a [u8],
cursor: usize,
}
impl<'a> Pig<'a> {
pub fn new(input: &'a [u8]) -> Self {
Pig {
input: input,
cursor: 0,
}
}
pub fn get_until(&mut self, c: u8) -> Fallible<&'a [u8]> {
if self.cursor >= self.input.len() {
bail!("input truncated");
}
let mut i = self.cursor;
while i < self.input.len() {
if self.input[i] == c {
let rv = &self.input[self.cursor..i];
self.cursor = i;
return Ok(rv);
}
i += 1;
}
let rv = &self.input[self.cursor..];
self.cursor = self.input.len();
Ok(rv)
}
pub fn get_quoted(&mut self, c: u8) -> Fallible<&'a [u8]> {
let length = self.input.len();
if self.cursor >= length || self.input[self.cursor] != c {
bail!("quoted string does not begin with quote character");
}
let start = self.cursor + 1;
let mut i = start;
while i < length {
while i < length && self.input[i] != c {
i += 1
}
if i == length {
bail!("unclosed quote");
}
if i == start {
return Ok(&self.input[i..i]);
}
if self.input[i - 1] == b'\\' {
// work backward looking for escaped backslashes
let mut j = i - 2;
let mut quote = true;
while j >= start && self.input[j] == b'\\' {
quote = !quote;
j -= 1;
}
if quote {
i += 1;
continue;
}
}
// none of the above matched, so we are at the end
self.cursor = i + 1;
return Ok(&self.input[start..i]);
}
unreachable!();
}
pub fn skip(&mut self, c: u8) -> Fallible<()> {
if self.cursor < self.input.len() && self.input[self.cursor] == c {
self.cursor += 1;
return Ok(());
}
bail!(
"expected character `{}`",
String::from_utf8(vec![c]).unwrap()
);
}
pub fn depleted(&self) -> bool {
self.cursor >= self.input.len()
}
}
#[cfg(test)]
mod test {
use super::Pig;
#[test]
fn test_get_until() {
let s = b"abc:123";
let mut pig = Pig::new(s);
assert_eq!(pig.get_until(b':').unwrap(), &s[..3]);
}
#[test]
fn test_get_until_empty() {
let s = b"abc:123";
let mut pig = Pig::new(s);
assert_eq!(pig.get_until(b'a').unwrap(), &s[..0]);
}
#[test]
fn test_get_until_not_found() {
let s = b"abc:123";
let mut pig = Pig::new(s);
assert_eq!(pig.get_until(b'/').unwrap(), &s[..]);
}
#[test]
fn test_get_quoted() {
let s = b"'abcd'efg";
let mut pig = Pig::new(s);
assert_eq!(pig.get_quoted(b'\'').unwrap(), &s[1..5]);
assert_eq!(pig.cursor, 6);
}
#[test]
fn test_get_quoted_unopened() {
let s = b"abcd'efg";
let mut pig = Pig::new(s);
assert!(pig.get_quoted(b'\'').is_err());
assert_eq!(pig.cursor, 0); // nothing consumed
}
#[test]
fn test_get_quoted_unclosed() {
let s = b"'abcdefg";
let mut pig = Pig::new(s);
assert!(pig.get_quoted(b'\'').is_err());
assert_eq!(pig.cursor, 0);
}
#[test]
fn test_get_quoted_escaped() {
let s = b"'abc\\'de'fg";
let mut pig = Pig::new(s);
assert_eq!(pig.get_quoted(b'\'').unwrap(), &s[1..8]);
assert_eq!(pig.cursor, 9);
}
#[test]
fn test_get_quoted_double_escaped() {
let s = b"'abc\\\\'de'fg";
let mut pig = Pig::new(s);
assert_eq!(pig.get_quoted(b'\'').unwrap(), &s[1..6]);
assert_eq!(pig.cursor, 7);
}
#[test]
fn test_get_quoted_triple_escaped() {
let s = b"'abc\\\\\\'de'fg";
let mut pig = Pig::new(s);
assert_eq!(pig.get_quoted(b'\'').unwrap(), &s[1..10]);
assert_eq!(pig.cursor, 11);
}
#[test]
fn test_get_quoted_all_escapes() {
let s = b"'\\\\\\'\\\\'fg";
let mut pig = Pig::new(s);
assert_eq!(pig.get_quoted(b'\'').unwrap(), &s[1..7]);
assert_eq!(pig.cursor, 8);
}
#[test]
fn test_skip_match() {
let s = b"foo";
let mut pig = Pig::new(s);
assert!(pig.skip(b'f').is_ok());
assert_eq!(pig.cursor, 1);
}
#[test]
fn test_skip_no_match() {
let s = b"foo";
let mut pig = Pig::new(s);
assert!(pig.skip(b'x').is_err());
assert_eq!(pig.cursor, 0); // nothing consumed
}
#[test]
fn test_skip_eos() {
let s = b"f";
let mut pig = Pig::new(s);
assert!(pig.skip(b'f').is_ok());
assert!(pig.skip(b'f').is_err());
}
}