Refactor keep-drop parsing into function, better error handling. #93
|
@ -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)),
|
||||||
|
|
Loading…
Reference in New Issue