diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 52d00b8d3..6dd147140 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -122,7 +122,7 @@ pub enum TemplateKind<'a> { pub(super) enum EaseKind { Rated(u8), Reviewed, - All, + Manually, } impl std::fmt::Display for EaseKind { @@ -132,7 +132,7 @@ impl std::fmt::Display for EaseKind { match self { Rated(u) => write!(f, " and ease = {}", u), Reviewed => write!(f, " and ease in (1, 2, 3, 4)"), - All => write!(f, ""), + Manually => write!(f, " and ease = 0"), } } } @@ -305,6 +305,7 @@ fn search_node_for_text_with_argument<'a>( "is" => parse_state(val)?, "flag" => parse_flag(val)?, "rated" => parse_rated(val)?, + "resched" => parse_resched(val)?, "dupe" => parse_dupes(val)?, "prop" => parse_prop(val)?, "re" => SearchNode::Regex(unescape_quotes(val)), @@ -378,14 +379,11 @@ fn parse_rated(val: &str) -> ParseResult> { let ease = match it.next() { Some(v) => { - let c: char = v.parse().unwrap(); - match c { - '0' | '1' | '2' | '3' | '4' => { - let n = c.to_digit(10).unwrap() as u8; - EaseKind::Rated(n) - } - 'a' => EaseKind::All, - _ => return Err(ParseError {}), + let u: u8 = v.parse().unwrap(); + if (1..5).contains(&u) { + EaseKind::Rated(u) + } else { + return Err(ParseError {}) } } None => EaseKind::Reviewed, @@ -394,6 +392,15 @@ fn parse_rated(val: &str) -> ParseResult> { Ok(SearchNode::Rated { days, ease }) } +/// eg resched:3 +fn parse_resched(val: &str) -> ParseResult> { + let mut it = val.splitn(1, ':'); + let days = it.next().unwrap().parse()?; + let ease = EaseKind::Manually; + + Ok(SearchNode::Rated { days, ease }) +} + /// eg dupes:1231,hello fn parse_dupes(val: &str) -> ParseResult { let mut it = val.splitn(2, ','); diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 61e5ee850..536fe39bd 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -159,7 +159,7 @@ fn write_rated(days: &u32, ease: &EaseKind) -> String { match ease { Rated(n) => format!("\"rated:{}:{}\"", days, n), Reviewed => format!("\"rated:{}\"", days), - All => format!("\"rated:{}:a\"", days), + Manually => format!("\"resched:{}\"", days), } }