diff options
| author | Teddy Wing | 2018-08-09 04:07:36 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-08-09 04:07:36 +0200 | 
| commit | 21f4c4d10a4d0c8fbf997e8b8de9dd39942f1ca8 (patch) | |
| tree | b8fa4fff2f0298d96b3c793afc43d52dfcbc6ba0 | |
| parent | d05b00eb8fa01a947fb1217b771444f43852499a (diff) | |
| download | dome-key-map-21f4c4d10a4d0c8fbf997e8b8de9dd39942f1ca8.tar.bz2 | |
Add parser for map action
For now just parses a string to a newline. In the future this will have
to be more complicated to deal with `<...>`-style special characters and
escaping (darn).
| -rw-r--r-- | src/lib.rs | 21 | 
1 files changed, 20 insertions, 1 deletions
| @@ -5,7 +5,8 @@ use std::collections::HashMap;  use combine::*;  use combine::parser::choice::or; -use combine::parser::char::{string, string_cmp}; +use combine::parser::char::{newline, string, string_cmp}; +use combine::parser::repeat::take_until;  #[derive(Debug, PartialEq)]  pub enum HeadphoneButton { @@ -72,6 +73,14 @@ where      many1(headphone_button())  } +fn action<I>() -> impl Parser<Input = I, Output = Action> +where +    I: Stream<Item = char>, +    I::Error: ParseError<I::Item, I::Range, I::Position>, +{ +    take_until(newline()) +} +  #[cfg(test)]  mod tests { @@ -120,4 +129,14 @@ mod tests {              HeadphoneButton::Play,          ]));      } + +    #[test] +    fn action_parses_string_to_end_of_line() { +        let text = "/usr/bin/say 'hello' +"; +        let expected: Action = "/usr/bin/say 'hello'".to_owned(); +        let result = action().parse(text).map(|t| t.0); + +        assert_eq!(result, Ok(expected)); +    }  } | 
