diff --git a/src/primitives.rs b/src/primitives.rs index df5c25f..b322b81 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -21,6 +21,18 @@ pub fn any_char(input: &str) -> ParseResult<&str, char, &str> { } } +pub fn one_of<'a>(items: &'static str) -> impl Parser<&'a str, &'a str, &'a str> { + move |input: &'a str| { + if let Some(ch) = input.chars().nth(0) { + if items.contains(ch) { + let (first, rest) = input.split_at(1); + return Ok((first, rest)); + } + } + Err(input) + } +} + pub fn pred(parser: P, pred_fn: F) -> impl Parser where P: Parser,