aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-01 17:12:31 +0100
committerTeddy Wing2018-11-01 17:12:31 +0100
commit70e127ba7d9ec2ad7419085d6bcf0e8d96adef47 (patch)
tree9f7026e5597e53b31ff6eb09cfab895243060d5c
parent6191caedd26752b6e699451bd602649f6f1200a1 (diff)
downloaddome-key-map-70e127ba7d9ec2ad7419085d6bcf0e8d96adef47.tar.bz2
parser::map_group(): Always parse to end of input
Previously, the modified input in `map_group_with_invalid_input_fails()` in this commit would fail with a result of `Ok` instead of `Err`. The `map_group()` parser would parse the first, correct line, and ignore the second, incorrect one. That's wrong. We want the whole parser to fail because it contains an invalid sequence. Do this by ensuring `eof()` follows all `definitions()`. This way we're guaranteed to always parse the whole input, and any errors within get surfaced.
-rw-r--r--src/parser.rs56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 3866a44..fe5b413 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -642,32 +642,34 @@ where
blank(),
eof(),
).map(|_| MapGroup::default()),
- definitions()
- .map(|definitions| {
- 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,
- }
- );
- },
- Definition::Mode(mode) => {
- map_group.modes.insert(
- mode.trigger,
- mode.maps,
- );
- },
- }
+ (
+ definitions(),
+ eof(),
+ ).map(|(definitions, _)| {
+ 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,
+ }
+ );
+ },
+ Definition::Mode(mode) => {
+ map_group.modes.insert(
+ mode.trigger,
+ mode.maps,
+ );
+ },
}
+ }
- map_group
- }),
+ map_group
+ }),
)
}
@@ -1369,13 +1371,14 @@ cmd <play> /usr/bin/say hello
#[test]
fn map_group_with_invalid_input_fails() {
- let text = "not-a-kind <play> <Nop>
+ let text = "map <up> <Up>
+not-a-kind <play> <Nop>
";
let result = map_group().easy_parse(State::new(text)).map(|t| t.0);
assert_eq!(result, Err(easy::Errors {
position: SourcePosition {
- line: 1,
+ line: 2,
column: 1,
},
errors: vec![
@@ -1387,6 +1390,7 @@ cmd <play> /usr/bin/say hello
easy::Error::Expected("whitespace".into()),
easy::Error::Expected("tab".into()),
easy::Error::Expected('#'.into()),
+ easy::Error::Expected("end of input".into()),
],
}));
}