Macro synom::terminated_list [] [src]

macro_rules! terminated_list {
    ($i:expr, punct!($sep:expr), $f:ident) => { ... };
    ($i:expr, $sepmac:ident!( $($separgs:tt)* ), $fmac:ident!( $($fargs:tt)* )) => { ... };
    ($i:expr, $sepmac:ident!( $($separgs:tt)* ), $f:expr) => { ... };
    ($i:expr, $sep:expr, $fmac:ident!( $($fargs:tt)* )) => { ... };
    ($i:expr, $sep:expr, $f:expr) => { ... };
}

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

You may also be looking for:

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);
}
extern crate syn;
#[macro_use] extern crate synom;

use syn::Ident;
use syn::parse::ident;

named!(run_on -> Vec<Ident>,
    terminated!(
        terminated_list!(keyword!("and"), preceded!(punct!("$"), ident)),
        punct!("...")
    )
);

fn main() {
    let input = "$expr and $ident and $pat and ...";

    let parsed = run_on(input).expect("run-on sentence");
    assert_eq!(parsed.len(), 3);
    assert_eq!(parsed[0], "expr");
    assert_eq!(parsed[1], "ident");
    assert_eq!(parsed[2], "pat");
}