macro_rules! ematch {
(chlist $chars:expr, $(from $from:expr, to $to:expr),*) => { ... };
(chlist $chars:expr, from2 $vfrom2:expr) => { ... };
}
Expand description
Generate a match expression with optional characters and a list of bounds
“String”, from ‘a’, to ‘b’, from ‘c’, to ‘d’ The first string, is a set of chars. Later you can write a list of tuples with ranges to validate
example
#[macro_use] extern crate dynparser;
use dynparser::parse;
fn main() {
let rules = rules!{
"main" => rep!(ematch!( chlist "cd",
from 'a', to 'b',
from 'j', to 'p'
), 0)
};
assert!(parse("aabcdj", &rules).is_ok())
}
You can also pass a list of chars and a vector of char bounds as next example
#[macro_use] extern crate dynparser;
use dynparser::parse;
fn main() {
let rules = rules!{
"main" => rep!(ematch!( chlist "cd",
from2 vec![
('a', 'b'),
('j', 'p')
]
), 0)
};
assert!(parse("aabcdj", &rules).is_ok())
}