aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-10-28 00:45:20 +0200
committerTeddy Wing2018-10-28 00:47:24 +0200
commit9c3bf2d09a21ac080ed1440c7c0df96b199e69bc (patch)
tree346606460ec9f7217de7964fca77e61516d578b6 /src
parentcc36984a6ba537398ac588f8f37482c4979c7d70 (diff)
downloaddome-key-map-9c3bf2d09a21ac080ed1440c7c0df96b199e69bc.tar.bz2
MapGroup: Move `parse_action()` to `MapAction`
Looking at the function, it makes more sense to put it inside a `MapAction` impl since it operates on a `MapAction`.
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 2644e0a..2243201 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -126,6 +126,34 @@ pub struct MapAction {
pub kind: MapKind,
}
+impl MapAction {
+ pub fn parse(&mut self) {
+ match self.kind {
+ MapKind::Map => {
+ let action = match self.action {
+ Action::String(ref s) => {
+ let input = State::new(s.as_str());
+
+ Some(
+ action_map()
+ .easy_parse(input)
+ .map(|t| t.0)
+ .unwrap()
+ )
+ },
+ _ => None,
+ };
+ if let Some(action) = action {
+ self.action = action;
+ }
+ },
+
+ // Commands don't get parsed. They remain `Action::String`s.
+ MapKind::Command => (),
+ }
+ }
+}
+
#[derive(Debug, PartialEq)]
struct Map {
trigger: Trigger,
@@ -163,41 +191,15 @@ impl MapGroup {
pub fn parse_actions(&mut self) {
for map_action in self.maps.values_mut() {
- Self::parse_action(map_action);
+ map_action.parse();
}
for mode in self.modes.values_mut() {
for map_action in mode.values_mut() {
- Self::parse_action(map_action);
+ map_action.parse();
}
}
}
-
- fn parse_action(map_action: &mut MapAction) {
- match map_action.kind {
- MapKind::Map => {
- let action = match map_action.action {
- Action::String(ref s) => {
- let input = State::new(s.as_str());
-
- Some(
- action_map()
- .easy_parse(input)
- .map(|t| t.0)
- .unwrap()
- )
- },
- _ => None,
- };
- if let Some(action) = action {
- map_action.action = action;
- }
- },
-
- // Commands don't get parsed. They remain `Action::String`s.
- MapKind::Command => (),
- }
- }
}