Macro cpp_synom::terminated_list [] [src]

macro_rules! terminated_list {
    ($i:expr, punct!($sep:expr), $f:expr) => { ... };
}

Zero or more values separated by some separator. A trailing separator is allowed.

The implementation requires that the first parameter is a punct! macro, and the second is a named parser.

  • Syntax: terminated_list!(punct!("..."), THING)
  • Output: Vec<THING>

You may also be looking for:

  • separated_list! - zero or more, allows trailing separator
  • separated_nonempty_list! - one or more values
  • many0! - zero or more, no separator
extern crate syn;
#[macro_use] extern crate synom;

use syn::Expr;
use syn::parse::expr;

named!(expr_list -> Vec<Expr>,
    terminated_list!(punct!(","), expr)
);

fn main() {
    let input = "1 + 1, things, Construct { this: thing },";

    let parsed = expr_list(input).expect("expr list");
    assert_eq!(parsed.len(), 3);
}