aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-09-29 14:00:02 +0200
committerTeddy Wing2018-09-29 14:00:02 +0200
commitb02e7366c3c4b9edb5afa0d012952fad369b66a9 (patch)
treef20872432c265b07603ce03900eb8ae26f1ee749 /src/parser.rs
parenta6f5f275e781bfa443e69b74a6c776eb6d970ded (diff)
downloaddome-key-map-b02e7366c3c4b9edb5afa0d012952fad369b66a9.tar.bz2
Change `parser::Action` to an enum
It will now be a different type of `Vec` depending on whether it represents a string map or a command. We'll have new parsers to parse the action definition in a more fine-grained way. The `String` variant is just there for temporary backward compatibility while I figure out parsing for the other two. Still need to update the tests for this change.
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 57abbbb..6ac52f1 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,5 +1,6 @@
use std::collections::HashMap;
+use autopilot;
use autopilot::key::{Flag, KeyCodeConvertible};
use combine::*;
use combine::easy::Errors as CombineErrors;
@@ -22,11 +23,48 @@ pub enum HeadphoneButton {
Down,
}
type Trigger = Vec<HeadphoneButton>;
-type Action = String;
+// type Action = String;
-enum Action2<'a, T: 'a + KeyCodeConvertible> {
- Map(&'a [(T, &'a [Flag])]),
- Command(&'a [&'a str]),
+// enum Action2<'a, T: 'a + KeyCodeConvertible> {
+// Map(&'a [(T, &'a [Flag])]),
+// Command(&'a [&'a str]),
+// }
+
+#[derive(Debug)]
+struct Character(autopilot::key::Character);
+
+impl PartialEq for Character {
+ fn eq(&self, other: &Character) -> bool {
+ (self.0).0 == (other.0).0
+ }
+}
+
+#[derive(Debug)]
+struct KeyCode(autopilot::key::Code);
+
+impl PartialEq for KeyCode {
+ fn eq(&self, other: &KeyCode) -> bool {
+ (self.0).0 == (other.0).0
+ }
+}
+
+#[derive(Debug, PartialEq)]
+enum KeyboardKey {
+ Character(Character),
+ KeyCode(KeyCode),
+}
+
+#[derive(Debug, PartialEq)]
+struct KeyboardKeyWithModifiers {
+ key: KeyboardKey,
+ flags: Vec<Flag>,
+}
+
+#[derive(Debug, PartialEq)]
+pub enum Action {
+ String(String),
+ Map(Vec<KeyboardKeyWithModifiers>),
+ Command(Vec<String>),
}
#[repr(C)]
@@ -123,6 +161,7 @@ where
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
take_until(newline())
+ .map(|action| Action::String(action))
}
fn whitespace_separator<I>() -> impl Parser<Input = I>