Macro abortable_parser::do_each[][src]

macro_rules! do_each {
    ($i : expr, $val : ident => $f : ident) => { ... };
    ($i : expr, $val : ident => $f : ident! ($($args : tt) *), $($rest : tt) *) => { ... };
    ($i : expr, _ => $f : ident! ($($args : tt) *), $($rest : tt) *) => { ... };
    ($i : expr, $val : ident => $f : ident, $($rest : tt) *) => { ... };
    ($i : expr, _ => $f : ident, $($rest : tt) *) => { ... };
    ($i : expr, ($($rest : tt) *)) => { ... };
}
Expand description

Captures a sequence of sub parsers output.

use abortable_parser::iter;
let input_str = "(foobar)";
let iter = iter::SliceIter::new(input_str.as_bytes());
let result = do_each!(iter,
    _ => text_token!("("),
    foo => text_token!("foo"),
    bar => text_token!("bar"),
    _ => text_token!(")"),
    (foo, bar) // This expression will be the result of the parse
);
if let Result::Complete(_, o) = result {
    assert_eq!("foo", o.0);
    assert_eq!("bar", o.1);
}

Or alternatively rather than a tuple as the output you can return a single expression.

let result = do_each!(iter,
    _ => text_token!("("),
    foo => text_token!("foo"),
    bar => text_token!("bar"),
    _ => text_token!(")"),
    (vec![foo, bar]) // Non tuple expression as a result.
);
if let Result::Complete(_, o) = result {
    assert_eq!(vec!["foo", "bar"], o);
}

The output from this combinator must be indicated by parentheses.