aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-08-09 04:07:36 +0200
committerTeddy Wing2018-08-09 04:07:36 +0200
commit21f4c4d10a4d0c8fbf997e8b8de9dd39942f1ca8 (patch)
treeb8fa4fff2f0298d96b3c793afc43d52dfcbc6ba0 /src/lib.rs
parentd05b00eb8fa01a947fb1217b771444f43852499a (diff)
downloaddome-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).
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index dc7b7bc..5fec41d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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));
+ }
}