Macro dynparser::rep

source ·
macro_rules! rep {
    ($e:expr, $min:expr) => { ... };
    ($e:expr, $min:expr, $max:expr) => { ... };
}
Expand description

repeat expression. You have to define minimum repetitions and optionally maximum repetitions (if missing, infinite)

example

#[macro_use]  extern crate dynparser;
use dynparser::parse;

fn main() {
    let rules = rules!{
       "main"   =>  rep!(lit!("a"), 0)
    };

    assert!(parse("aaaaaaaa", &rules).is_ok())
}

repeating from 0 to infinite

#[macro_use]  extern crate dynparser;
use dynparser::parse;

fn main() {
    let rules = rules!{
       "main"   =>  rep!(lit!("a"), 0, 3)
    };

    assert!(parse("aaa", &rules).is_ok())
}