nom-derive

License: MIT Apache License 2.0 docs.rs Build Status Crates.io Version

Overview

nom-derive is a custom derive attribute, to derive [nom] parsers automatically from the structure definition.

It is not meant to replace [nom], but to provide a quick and easy way to generate parsers for structures, especially for simple structures. This crate aims at simplifying common cases. In some cases, writing the parser manually will remain more efficient.

Feedback welcome !

#[derive(Nom)]

This crate exposes a single custom-derive macro Nom which implements parse for the struct it is applied to.

The goal of this project is that:

nom-derive adds declarative parsing to nom. It also allows mixing with procedural parsing easily, making writing parsers for byte-encoded formats very easy.

For example:

```rust use nom_derive::Nom;

[derive(Nom)]

struct S { a: u32, b: u16, c: u16 } ```

This adds a static method parse to S, with the following signature: rust,ignore impl S { pub fn parse(i: &[u8]) -> nom::IResult(&[u8], S); }

To parse input, just call let res = S::parse(input);.

For extensive documentation of all attributes and examples, see the Nom derive attribute documentation.

Many examples are provided, and more can be found in the project tests.

Combinators visibility

All inferred parsers will generate code with absolute type path, so there is no need to add use statements for them. However, if you use any combinator directly (or in a Parse statement, for ex.), it has to be imported as usual.

That is probably not going to change, since * a proc_macro cannot export items other than functions tagged with #[proc_macro_derive] * there are variants of combinators with the same names (complete/streaming, bits/bytes), so re-exporting them would create side-effects.

Debug tips

Changes

0.7.2

0.7.1

0.7.0

0.6.3

0.6.2

0.6.1

0.6.0

0.5.0

0.4.0

0.3.0

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.