Refactor keep-drop parsing into function, better error handling. #93

Merged
projectmoon merged 2 commits from keep-drop-refactoring into master 2021-09-30 21:16:04 +00:00
1 changed files with 2 additions and 2 deletions
Showing only changes of commit ef5b4cb69b - Show all commits

View File

@ -84,12 +84,12 @@ fn parse_keep_or_drop<'a>(input: &'a str, count: u32) -> IResult<&'a str, KeepOr
use ParsedKeepOrDrop::*; use ParsedKeepOrDrop::*;
let keep_drop: KeepOrDrop = match (keep, drop) { let keep_drop: KeepOrDrop = match (keep, drop) {
//Valid Keep expression. //Potential valid Keep expression.
(Keep(keep), NotPresent) => match keep.parse().map_err(|_| too_big!(input))? { (Keep(keep), NotPresent) => match keep.parse().map_err(|_| too_big!(input))? {
_i if _i > count || _i == 0 => Ok(KeepOrDrop::None), _i if _i > count || _i == 0 => Ok(KeepOrDrop::None),
i => Ok(KeepOrDrop::Keep(i)), i => Ok(KeepOrDrop::Keep(i)),
}, },
//Valid Drop expression. //Potential valid Drop expression.
(NotPresent, Drop(drop)) => match drop.parse().map_err(|_| too_big!(input))? { (NotPresent, Drop(drop)) => match drop.parse().map_err(|_| too_big!(input))? {
_i if _i >= count => Ok(KeepOrDrop::None), _i if _i >= count => Ok(KeepOrDrop::None),
i => Ok(KeepOrDrop::Drop(i)), i => Ok(KeepOrDrop::Drop(i)),