nom-parse-macros

Crates.ionom-parse-macros
lib.rsnom-parse-macros
version
sourcesrc
created_at2025-01-06 14:37:15.78917
updated_at2025-01-08 22:10:02.927523
descriptionProcedural macros for generating parser functions for the nom libary
homepagehttps://github.com/marcdejonge/nom-parse-macros
repositoryhttps://github.com/marcdejonge/nom-parse-macros.git
max_upload_size
id1505662
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Marc de Jonge (marcdejonge)

documentation

README

nom-parse-macros

CI Crates.io Documentation

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

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.

Commit count: 25

cargo fmt