Macro synom::separated_list
[−]
[src]
macro_rules! separated_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. Does not allow a trailing seperator.
- Syntax:
separated_list!(punct!("..."), THING)
- Output:
Vec<THING>
You may also be looking for:
separated_nonempty_list!
- one or more valuesterminated_list!
- zero or more, allows trailing separatormany0!
- 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>, separated_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!( separated_list!(keyword!("and"), preceded!(punct!("$"), ident)), punct!("...") ) ); fn main() { let input = "$expr and $ident and $pat ..."; 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"); }