granit_parser/macros.rs
1//! Public macro for constructing [`Options`](crate::Options) without struct literal syntax.
2//!
3//! This macro keeps call sites ergonomic while allowing the option struct to gain fields without a
4//! breaking change.
5
6/// Construct [`Options`](crate::Options) from its defaults and a list of field assignments.
7///
8/// # Examples
9///
10/// ```rust
11/// let options = granit_parser::options! {
12/// emit_comments: false,
13/// simple_key_max_lookahead: 2048,
14/// };
15///
16/// assert!(!options.emit_comments);
17/// assert_eq!(options.simple_key_max_lookahead, 2048);
18/// assert_eq!(options.flow_nesting_limit, 255);
19/// assert_eq!(options.block_nesting_limit, 255);
20/// ```
21#[macro_export]
22macro_rules! options {
23 ($($(#[$attr:meta])* $field:ident : $value:expr),* $(,)?) => {{
24 #[allow(unused_mut)]
25 let mut options = $crate::Options::default();
26 $($(#[$attr])* { options.$field = $value; })*
27 options
28 }};
29}