Function neure::re::pair_vector
source · pub fn pair_vector<K, V: Clone>(
val: impl IntoIterator<Item = (K, V)>
) -> PairVector<K, V>Expand description
Iterate over the vector and match the regex against the Context.
It will return the value of first pair that matches.
Example
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum C {
Var,
Ptr,
Ref,
}
let ty = neu::ascii_alphabetic().repeat_one_more();
let id = neu::ascii_alphabetic().repeat_one_more();
let var = ty.sep_once("", id);
let ptr = ty.sep_once("*", id);
let r#ref = ty.sep_once("&", id);
let vec = re::pair_vector([(var, C::Var), (ptr, C::Ptr), (r#ref, C::Ref)]);
let sp = neu::whitespace().repeat_full();
assert_eq!(
CharsCtx::new("int a").ignore(sp).ctor(&vec)?,
(("int", "a"), C::Var)
);
assert_eq!(
CharsCtx::new("int *a").ignore(sp).ctor(&vec)?,
(("int", "a"), C::Ptr)
);
assert_eq!(
CharsCtx::new("int &a").ignore(sp).ctor(&vec)?,
(("int", "a"), C::Ref)
);
Ok(())