voa_core/macros.rs
1//! Macros for the use in identifiers.
2
3/// Take a `dyn Iterator<Item = &char>` and return a closure that calls `.iter()` and maps
4/// the values onto [winnow::error::StrContextValue::CharLiteral].
5///
6/// # Example
7///
8/// ```
9/// use voa_core::iter_char_context;
10/// use winnow::{ModalResult, Parser, combinator::cut_err, token::one_of};
11///
12/// fn parser(input: &mut &str) -> ModalResult<char> {
13/// let accepted_characters = ['a', 'b', 'c'];
14/// cut_err(one_of(accepted_characters))
15/// .context_with(iter_char_context!(accepted_characters))
16/// .parse_next(input)
17/// }
18///
19/// assert!(parser.parse("a").is_ok());
20/// ```
21#[macro_export]
22macro_rules! iter_char_context {
23 ($iter:expr) => {
24 || {
25 use winnow::error::{StrContext, StrContextValue};
26 $iter
27 .iter()
28 .map(|c| StrContext::Expected(StrContextValue::CharLiteral(*c)))
29 }
30 };
31}