aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-01 04:37:33 +0100
committerTeddy Wing2018-11-01 04:41:59 +0100
commitfca324396c762e034ee30aec3f7ffa0ce7de5516 (patch)
tree3323cea38a9c7de601e3b0fd828d2b20d42ca9b4
parent6658bb238d87f2182f3c2a6119b86c5fdea9b36b (diff)
downloaddome-key-map-fca324396c762e034ee30aec3f7ffa0ce7de5516.tar.bz2
parser: Parsing an empty string gives a default `MapGroup`
Since the most recent `many1` change (09c0a432fb339a2218096bb9a4398fb86301488f), the parser fails on end-of-input, or an empty string. In that case, it should instead return the default `MapGroup`. Add a special case for this.
-rw-r--r--src/parser.rs74
1 files changed, 43 insertions, 31 deletions
diff --git a/src/parser.rs b/src/parser.rs
index c7bccc0..1c21510 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -645,39 +645,42 @@ where
I: Stream<Item = char>,
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
- definitions()
- .map(|definitions| {
- // MapGroup {
- // maps: ,
- // modes: ,
- // }
-
- let mut map_group = MapGroup::default();
-
- for definition in definitions {
- match definition {
- Definition::Map(map) => {
- map_group.maps.insert(
- // map.trigger,
- // MapAction {
- // action: map.action,
- // kind: map.kind,
- // }
- map.0,
- map.1,
- );
- },
- Definition::Mode(mode) => {
- map_group.modes.insert(
- mode.trigger,
- mode.maps,
- );
- },
+ or(
+ definitions()
+ .map(|definitions| {
+ // MapGroup {
+ // maps: ,
+ // modes: ,
+ // }
+
+ let mut map_group = MapGroup::default();
+
+ for definition in definitions {
+ match definition {
+ Definition::Map(map) => {
+ map_group.maps.insert(
+ // map.trigger,
+ // MapAction {
+ // action: map.action,
+ // kind: map.kind,
+ // }
+ map.0,
+ map.1,
+ );
+ },
+ Definition::Mode(mode) => {
+ map_group.modes.insert(
+ mode.trigger,
+ mode.maps,
+ );
+ },
+ }
}
- }
- map_group
- })
+ map_group
+ }),
+ eof().map(|()| MapGroup::default()),
+ )
}
fn comment<I>() -> impl Parser<Input = I>
@@ -1361,6 +1364,15 @@ cmd <play> /usr/bin/say hello
}
#[test]
+ fn map_group_empty_input_does_not_fail() {
+ let text = "";
+ let result = map_group().easy_parse(text).map(|t| t.0);
+ let expected = MapGroup::default();
+
+ assert_eq!(result, Ok(expected));
+ }
+
+ #[test]
fn map_group_with_invalid_input_fails() {
let text = "not-a-kind <play> <Nop>
";