2 unstable releases
new 0.2.0 | Jan 8, 2025 |
---|---|
0.1.0 | Jan 6, 2025 |
#1645 in Parser implementations
140 downloads per month
42KB
747 lines
nom-parse-macros
This crate provides 2 macros to generate a ParseFrom
implementation for a struct
or enum using the provided nom expression(s). The expression given should return a
tuple for the parsed fields.
There are 2 separate macros available, parse_from
and parse_match
. The first
one is really generic and can be useful in many cases, since you have the full
flexibility of nom functions and combinators. The second one is a very simple
one that matches a string verbatim. This is useful when you have a very simple
format that you want to parse.
As a quick example, consider the following struct:
use nom_parse_macros::parse_from;
#[parse_from(tuple(be_32, be_u16))]
struct MyStruct {
a: u32,
b: u16,
}
After this, you can easily call MyStruct::parse
with a byte array and get a
parsed instance back. You have many of the nom functions available to you, so
you can parse more complex structures as well. Look at the documentation for
more examples and more explanation on how to use the macros.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~1.9–2.6MB
~51K SLoC