Skip to main content

impl_block_properties_parser

Macro impl_block_properties_parser 

Source
macro_rules! impl_block_properties_parser {
    (@build_or_chain $first_parser_var:ident) => { ... };
    (@build_or_chain $first_parser_var:ident, $($rest_parser_vars:ident),+) => { ... };
    (
        $any_property_let_name:ident: $PropEnumType:ty = {
            $(
                $var_name:ident = $parser_call_expr:expr => $value_mapper_fn:expr
            ),+ $(,)? // Allow trailing comma
        }
    ) => { ... };
}
Expand description

Macro to define individual property parsers and combine them with .or(). When this Macro is used, it is necrssary to have chumsky’s .or() and .map() in the scope.

Usage:

impl_block_properties_parser! {
    // Output variable name for the combined parser: Its type will be Box<dyn Parser<..., Output = $PropEnumType, ...>>
    any_property_variable_name: YourPropertyEnumType = {
        // var_name = parser_call_expr => enum_variant_constructor_or_mapper_fn
        p_some_bool = some_parser_that_outputs_bool("some_key") => YourPropertyEnumType::SomeBool,
        p_some_num  = some_parser_that_outputs_u32("num_key")  => YourPropertyEnumType::SomeNum,
        // ...
    }
}