Expand description
Procedural macro for the arguments! { ... }
macro-argument parser for seam macros.
TODO: Convert all panic!(..)
calls to actual compiler errors.
Macros§
- Macro that generates an argument parser and builds a custom struct holding provided arguments, given a schema and the list of arguments. Example:
let (parser, args) = arguments! { [¶ms] mandatory(1..=3): literal, mandatory(4): number fn(n: ParseNode) { let n = extract_number(n)?; let Ok(n): u32 = n.value.parse() else { return Err("Argument must be an integer."); } if n % 2 == 0 { Ok(()) } else { Err("Integer must be even.") } }, optional("trailing"): literal["true", "false"], rest: number }?; println!("first arg {:?}", args.number.1); // a literal (Node<'a>). println!("second arg {:?}", args.number.2); // a literal (Node<'a>). println!("third arg {:?}", args.number.3); // a literal (Node<'a>). println!("fourth arg {:?}", args.number.4); // an even integer (Node<'a>). if let Some(named) = args.trailing { println!("named arg {:?}", named); // the literal "true" or "false". } for arg in args.rest { println!("trailing arg: {:?}", arg); // trailing number args. }