#nom #macro #remove #boilerplate #pattern #fields #function-like

nom-fields

Provides a single function-like macro that removes some boilerplate from a common pattern when using nom

2 releases

0.1.1 Apr 9, 2020
0.1.0 Apr 6, 2020

#2535 in Rust patterns

30 downloads per month
Used in 2 crates

MIT/Apache

4KB

Docs License

nom-fields

This crate provides a single function-like macro that removes some boilerplate from a common pattern when using the parsing framework nom.

With this macro, the following parser...

nom::combinator::map(
    nom::sequence::tuple((
        some_parser,
        some_other_parser,
        a_third_parser
    )),
    |(some_field, some_other_field, a_third_field)| SomeStruct {
        some_field,
        some_other_field,
        a_third_field
    }
)(input)

...becomes this:

nom_fields::fields!(SomeStruct:
    some_field = some_parser,
    some_other_field = some_other_parser,
    a_third_field = a_third_parser
)(input)

lib.rs:

This crate provides a single function-like macro that removes some boilerplate from a common pattern when using the parsing framework nom.

With this macro, the following parser...

nom::combinator::map(
    nom::sequence::tuple((
        some_parser,
        some_other_parser,
        a_third_parser
    )),
    |(some_field, some_other_field, a_third_field)| SomeStruct {
        some_field,
        some_other_field,
        a_third_field
    }
)(input)

...becomes this:

nom_fields::fields!(SomeStruct:
    some_field = some_parser,
    some_other_field = some_other_parser,
    a_third_field = a_third_parser
)(input)

No runtime deps