Function neure::re::vector

source ·
pub fn vector<T>(val: impl IntoIterator<Item = T>) -> Vector<T>
Expand description

Iterate over the vector and match the regex against the Context. It will return the result of first regex that matches.

Example

    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::vector([var, ptr, r#ref]);
    let sp = neu::whitespace().repeat_full();

    assert_eq!(CharsCtx::new("int a").ignore(sp).ctor(&vec)?, ("int", "a"));
    assert_eq!(CharsCtx::new("int *a").ignore(sp).ctor(&vec)?, ("int", "a"));
    assert_eq!(CharsCtx::new("int &a").ignore(sp).ctor(&vec)?, ("int", "a"));
    Ok(())