From 21f4c4d10a4d0c8fbf997e8b8de9dd39942f1ca8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 9 Aug 2018 04:07:36 +0200 Subject: 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). --- src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') 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() -> impl Parser +where + I: Stream, + I::Error: ParseError, +{ + 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)); + } } -- cgit v1.2.3