aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 0cfac2e..7ccaf6b 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -72,6 +72,7 @@ pub enum KeyboardKey {
Character(Character),
KeyCode(KeyCode),
NXKey(NXKey),
+ Nop,
}
#[derive(Debug, PartialEq)]
@@ -107,6 +108,7 @@ impl KeyboardKeyWithModifiers {
dkess_press_key(nx, flags);
}
},
+ KeyboardKey::Nop => (),
}
}
}
@@ -323,7 +325,7 @@ where
between(
token('<'),
token('>'),
- or(
+ choice((
try((
many(key_modifier()),
or(
@@ -336,8 +338,9 @@ where
action_character().map(|c|
KeyboardKey::Character(Character::new(c))
),
- ))
- )
+ )),
+ try((value(vec![]), nop())),
+ ))
).map(|(modifiers, key): (Vec<Flag>, KeyboardKey)| {
KeyboardKeyWithModifiers::new(
key,
@@ -492,6 +495,15 @@ where
)
}
+fn nop<I>() -> impl Parser<Input = I, Output = KeyboardKey>
+where
+ I: Stream<Item = char>,
+ I::Error: ParseError<I::Item, I::Range, I::Position>,
+{
+ string_case_insensitive("Nop")
+ .map(|_| KeyboardKey::Nop)
+}
+
fn whitespace_separator<I>() -> impl Parser<Input = I>
where
I: Stream<Item = char>,
@@ -1016,6 +1028,21 @@ mod tests {
}
#[test]
+ fn action_parses_map_with_nop() {
+ let text = "<Nop>";
+
+ let expected = Action::Map(vec![
+ KeyboardKeyWithModifiers::new(
+ KeyboardKey::Nop,
+ vec![],
+ ),
+ ]);
+ let result = action_map().easy_parse(text).map(|t| t.0);
+
+ assert_eq!(result, Ok(expected));
+ }
+
+ #[test]
fn map_parses_map_line() {
let text = "map <play><down> test
";