{"id":13599814,"url":"https://github.com/rust-bakery/nom-derive","last_synced_at":"2025-04-10T17:32:32.421Z","repository":{"id":34242627,"uuid":"172038749","full_name":"rust-bakery/nom-derive","owner":"rust-bakery","description":"Declarative parsing for Rust, using a custom derive and nom","archived":false,"fork":false,"pushed_at":"2023-05-29T03:58:33.000Z","size":253,"stargazers_count":66,"open_issues_count":18,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-10T16:26:36.945Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-bakery.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-02-22T09:40:39.000Z","updated_at":"2024-07-27T04:23:29.000Z","dependencies_parsed_at":"2024-04-21T23:28:16.453Z","dependency_job_id":null,"html_url":"https://github.com/rust-bakery/nom-derive","commit_stats":{"total_commits":182,"total_committers":8,"mean_commits":22.75,"dds":0.05494505494505497,"last_synced_commit":"c8f384f102ae6c4543b9882812f11f56a886d048"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-derive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-derive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-derive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-derive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-bakery","download_url":"https://codeload.github.com/rust-bakery/nom-derive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223442664,"owners_count":17145815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T17:01:12.380Z","updated_at":"2024-11-07T01:30:55.748Z","avatar_url":"https://github.com/rust-bakery.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003c!-- cargo-sync-readme start --\u003e\n\n# nom-derive\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE-MIT)\n[![Apache License 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE-APACHE)\n[![docs.rs](https://docs.rs/nom-derive/badge.svg)](https://docs.rs/nom-derive)\n[![Build Status](https://travis-ci.org/chifflier/nom-derive.svg?branch=master)](https://travis-ci.org/chifflier/nom-derive)\n[![Crates.io Version](https://img.shields.io/crates/v/nom-derive.svg)](https://crates.io/crates/nom-derive)\n\n## Overview\n\nnom-derive is a custom derive attribute, to derive [nom] parsers automatically from the structure definition.\n\nIt is not meant to replace [nom], but to provide a quick and easy way to generate parsers for\nstructures, especially for simple structures. This crate aims at simplifying common cases.\nIn some cases, writing the parser manually will remain more efficient.\n\n- [API documentation](https://docs.rs/nom-derive)\n- The [docs::Nom] pseudo-module. This is the main\n  documentation for the `Nom` attribute, with all possible options and many examples.\n\n*Feedback welcome !*\n\n## `#[derive(Nom)]`\n\nThis crate exposes a single custom-derive macro `Nom` which\nimplements `parse` for the struct it is applied to.\n\nThe goal of this project is that:\n\n* `derive(Nom)` should be enough for you to derive [nom] parsers for simple\n  structures easily, without having to write it manually\n* it allows overriding any parsing method by your own\n* it allows using generated parsing functions along with handwritten parsers and\n  combining them without efforts\n* it remains as fast as nom\n\n`nom-derive` adds declarative parsing to `nom`. It also allows mixing with\nprocedural parsing easily, making writing parsers for byte-encoded formats\nvery easy.\n\nFor example:\n\n```rust\nuse nom_derive::*;\n\n#[derive(Nom)]\nstruct S {\n  a: u32,\n  b: u16,\n  c: u16\n}\n```\n\nThis adds static method `parse` to `S`. The generated code looks\nlike:\n```rust,ignore\nimpl S {\n    pub fn parse(i: \u0026[u8]) -\u003e nom::IResult(\u0026[u8], S) {\n        let (i, a) = be_u32(i)?;\n        let (i, b) = be_u16(i)?;\n        let (i, c) = be_u16(i)?;\n        Ok((i, S{ a, b, c }))\n    }\n}\n```\n\nTo parse input, just call `let res = S::parse(input);`.\n\nFor extensive documentation of all attributes and examples, see the documentation of [docs::Nom]\ncustom derive attribute.\n\nMany examples are provided, and more can be found in the [project\ntests](https://github.com/rust-bakery/nom-derive/tree/master/tests).\n\n## Combinators visibility\n\nAll inferred parsers will generate code with absolute type path, so there is no need\nto add `use` statements for them. However, if you use any combinator directly (or in a `Parse`\nstatement, for ex.), it has to be imported as usual.\n\nThat is probably not going to change, since\n* a proc_macro cannot export items other than functions tagged with `#[proc_macro_derive]`\n* there are variants of combinators with the same names (complete/streaming, bits/bytes), so\n  re-exporting them would create side-effects.\n\n## Debug tips\n\n* If the generated parser does not compile, add `#[nom(DebugDerive)]` to the structure.\n  It will dump the generated parser to `stderr`.\n* If the generated parser fails at runtime, try adding `#[nom(Debug)]` to the structure or\n  to fields. It wraps subparsers in `dbg_dmp` and will print the field name and input to\n  `stderr` if the parser fails.\n\n[nom]: https://github.com/geal/nom\n\u003c!-- cargo-sync-readme end --\u003e\n\n## Changes\n\nSee `CHANGELOG.md`, and `UPGRADING.md` for instructions for upgrading major versions.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom-derive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-bakery%2Fnom-derive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom-derive/lists"}