From 16cd3895f7b111544927d71904aab912d9abbf59 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 Sep 2018 01:04:53 +0200 Subject: Try to propagate KeyCodeConvertible from Action to everywhere Such a pain. As soon as I clear one set of compilation errors, another set crops up. The last one was like the following: error[E0277]: the trait bound `K: std::default::Default` is not satisfied --> src/cocoa_bridge.rs:117:1 | 117 | / pub extern "C" fn state_new() -> *mut State 118 | | where K: KeyCodeConvertible { 119 | | Box::into_raw(Box::new(State::default())) 120 | | } | |_^ the trait `std::default::Default` is not implemented for `K` | = help: consider adding a `where K: std::default::Default` bound note: required by `cocoa_bridge::State` --> src/cocoa_bridge.rs:100:1 | 100 | / pub struct State 101 | | where K: Default { 102 | | in_mode: Option>, 103 | | map_group: Option>, 104 | | } | |_^ error[E0277]: the trait bound `K: std::default::Default` is not satisfied I'm done with this. Just going to make a darn enum of 'autopilot's `Character` and `KeyCode` structs so I don't have to deal with this mess. --- src/parser.rs | 78 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 27 deletions(-) (limited to 'src/parser.rs') diff --git a/src/parser.rs b/src/parser.rs index 57abbbb..7fcea71 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -22,11 +22,28 @@ pub enum HeadphoneButton { Down, } type Trigger = Vec; -type Action = String; - -enum Action2<'a, T: 'a + KeyCodeConvertible> { - Map(&'a [(T, &'a [Flag])]), - Command(&'a [&'a str]), +// type Action = String; + +// enum Action<'a, T: 'a + KeyCodeConvertible> { +// String(String), +// Map(&'a [(T, &'a [Flag])]), +// Command(&'a [&'a str]), +// } + +// struct KeyboardKey { +// key: , +// flags: &[Flags], +// } + +// enum Action { +// String(String), +// Map(Vec<(T, Vec)>), +// Command(Vec), +// } +enum Action { + String(String), + Map(Vec<(K, Vec)>), + Command(Vec), } #[repr(C)] @@ -37,42 +54,42 @@ pub enum MapKind { } #[derive(Debug, PartialEq)] -pub struct MapAction { - pub action: Action, +pub struct MapAction { + pub action: Action, pub kind: MapKind, } #[derive(Debug, PartialEq)] -struct Map { +struct Map { trigger: Trigger, - action: Action, + action: Action, kind: MapKind, } -type MapCollection = HashMap; +type MapCollection = HashMap>; #[derive(Debug, PartialEq)] -struct Mode { +struct Mode { trigger: Trigger, - maps: MapCollection, + maps: MapCollection, } #[derive(Debug, PartialEq)] -pub struct MapGroup { - pub maps: MapCollection, - pub modes: HashMap, +pub struct MapGroup { + pub maps: MapCollection, + pub modes: HashMap>, } #[derive(Debug, PartialEq)] -enum Definition { - Map(Map), - Mode(Mode), +enum Definition { + Map(Map), + Mode(Mode), } -impl MapGroup { +impl MapGroup { pub fn parse( mappings: &str - ) -> Result> { + ) -> Result, CombineErrors> { let input = State::new(mappings); map_group().easy_parse(input).map(|t| t.0) } @@ -117,12 +134,14 @@ where many1(headphone_button()) } -fn action() -> impl Parser +fn action() -> impl Parser> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { take_until(newline()) + .map(|action| Action::String(action)) } fn whitespace_separator() -> impl Parser @@ -133,10 +152,11 @@ where skip_many1(space().or(tab())) } -fn map() -> impl Parser +fn map() -> impl Parser> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { ( map_kind(), @@ -153,14 +173,15 @@ where ) } -fn map_collection() -> impl Parser +fn map_collection() -> impl Parser> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { ( blank(), - many::, _>(map().skip(blank())), + many::>, _>(map().skip(blank())), ).map(|(_, collection)| { let mut maps = HashMap::new(); @@ -178,10 +199,11 @@ where }) } -fn mode() -> impl Parser +fn mode() -> impl Parser> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { ( string("mode"), @@ -199,10 +221,11 @@ where ) } -fn definitions() -> impl Parser> +fn definitions() -> impl Parser>> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { ( blank(), @@ -215,10 +238,11 @@ where ).map(|(_, definitions)| definitions) } -fn map_group() -> impl Parser +fn map_group() -> impl Parser> where I: Stream, I::Error: ParseError, + K: KeyCodeConvertible, { definitions() .map(|definitions| { -- cgit v1.2.3