Function combine::parser::token::tokens [−][src]
pub fn tokens<C, E, T, Input>(
cmp: C,
expected: E,
tokens: T
) -> Tokens<C, E, T, Input> where
C: FnMut(T::Item, Input::Token) -> bool,
T: Clone + IntoIterator,
Input: Stream,
Expand description
Parses multiple tokens.
Consumes items from the input and compares them to the values from tokens
using the
comparison function cmp
. Succeeds if all the items from tokens
are matched in the input
stream and fails otherwise with expected
used as part of the error.
let result = tokens(|l, r| l.eq_ignore_ascii_case(&r), "abc", "abc".chars()) .parse("AbC") .map(|x| x.0.as_str()); assert_eq!(result, Ok("abc")); let result = tokens( |&l, r| (if l < r { r - l } else { l - r }) <= 2, error::Range(&b"025"[..]), &b"025"[..] ) .parse(&b"123"[..]) .map(|x| x.0); assert_eq!(result, Ok(&b"025"[..]));