{"id":13416008,"url":"https://github.com/rust-bakery/nom","last_synced_at":"2025-11-11T11:35:30.599Z","repository":{"id":23659242,"uuid":"27029984","full_name":"rust-bakery/nom","owner":"rust-bakery","description":"Rust parser combinator framework","archived":false,"fork":false,"pushed_at":"2025-02-08T15:04:14.000Z","size":10821,"stargazers_count":9881,"open_issues_count":269,"forks_count":831,"subscribers_count":84,"default_branch":"main","last_synced_at":"2025-05-12T18:19:14.293Z","etag":null,"topics":["byte-array","grammar","nom","parse","parser","parser-combinators","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-23T11:16:23.000Z","updated_at":"2025-05-12T16:31:11.000Z","dependencies_parsed_at":"2023-01-13T23:39:06.364Z","dependency_job_id":"a5580986-b579-48a4-87b6-4e78563871bb","html_url":"https://github.com/rust-bakery/nom","commit_stats":{"total_commits":2380,"total_committers":384,"mean_commits":6.197916666666667,"dds":0.4609243697478992,"last_synced_commit":"54557471141b73ca3b2d07be88d6709a43495b10"},"previous_names":["geal/nom"],"tags_count":94,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-bakery","download_url":"https://codeload.github.com/rust-bakery/nom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253795162,"owners_count":21965488,"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":["byte-array","grammar","nom","parse","parser","parser-combinators","rust"],"created_at":"2024-07-30T21:00:53.612Z","updated_at":"2025-11-11T11:35:30.563Z","avatar_url":"https://github.com/rust-bakery.png","language":"Rust","readme":"# nom, eating data byte by byte\n\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Join the chat at https://gitter.im/Geal/nom](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Geal/nom?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://github.com/rust-bakery/nom/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-bakery/nom/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/rust-bakery/nom/badge.svg?branch=main)](https://coveralls.io/github/rust-bakery/nom?branch=main)\n[![crates.io Version](https://img.shields.io/crates/v/nom.svg)](https://crates.io/crates/nom)\n[![Minimum rustc version](https://img.shields.io/badge/rustc-1.65.0+-lightgray.svg)](#rust-version-requirements-msrv)\n\nnom is a parser combinators library written in Rust. Its goal is to provide tools\nto build safe parsers without compromising the speed or memory consumption. To\nthat end, it uses extensively Rust's *strong typing* and *memory safety* to produce\nfast and correct parsers, and provides functions, macros and traits to abstract most of the\nerror prone plumbing.\n\n![nom logo in CC0 license, by Ange Albertini](https://raw.githubusercontent.com/Geal/nom/main/assets/nom.png)\n\n*nom will happily take a byte out of your files :)*\n\n\u003c!-- toc --\u003e\n\n- [Example](#example)\n- [Documentation](#documentation)\n- [Why use nom?](#why-use-nom)\n    - [Binary format parsers](#binary-format-parsers)\n    - [Text format parsers](#text-format-parsers)\n    - [Programming language parsers](#programming-language-parsers)\n    - [Streaming formats](#streaming-formats)\n- [Parser combinators](#parser-combinators)\n- [Technical features](#technical-features)\n- [Rust version requirements](#rust-version-requirements-msrv)\n- [Installation](#installation)\n- [Related projects](#related-projects)\n- [Parsers written with nom](#parsers-written-with-nom)\n- [Contributors](#contributors)\n\n\u003c!-- tocstop --\u003e\n\n## Example\n\n[Hexadecimal color](https://developer.mozilla.org/en-US/docs/Web/CSS/color) parser:\n\n```rust\nuse nom::{\n  bytes::complete::{tag, take_while_m_n},\n  combinator::map_res,\n  sequence::Tuple,\n  IResult,\n  Parser,\n};\n\n#[derive(Debug, PartialEq)]\npub struct Color {\n  pub red: u8,\n  pub green: u8,\n  pub blue: u8,\n}\n\nfn from_hex(input: \u0026str) -\u003e Result\u003cu8, std::num::ParseIntError\u003e {\n  u8::from_str_radix(input, 16)\n}\n\nfn is_hex_digit(c: char) -\u003e bool {\n  c.is_digit(16)\n}\n\nfn hex_primary(input: \u0026str) -\u003e IResult\u003c\u0026str, u8\u003e {\n  map_res(\n    take_while_m_n(2, 2, is_hex_digit),\n    from_hex\n  ).parse(input)\n}\n\nfn hex_color(input: \u0026str) -\u003e IResult\u003c\u0026str, Color\u003e {\n  let (input, _) = tag(\"#\")(input)?;\n  let (input, (red, green, blue)) = (hex_primary, hex_primary, hex_primary).parse(input)?;\n  Ok((input, Color { red, green, blue }))\n}\n\nfn main() {\n  println!(\"{:?}\", hex_color(\"#2F14DF\"))\n}\n\n#[test]\nfn parse_color() {\n  assert_eq!(\n    hex_color(\"#2F14DF\"),\n    Ok((\n      \"\",\n      Color {\n        red: 47,\n        green: 20,\n        blue: 223,\n      }\n    ))\n  );\n}\n```\n\n## Documentation\n\n- [Reference documentation](https://docs.rs/nom)\n- [The Nominomicon: A Guide To Using Nom](https://tfpk.github.io/nominomicon/)\n- [Various design documents and tutorials](https://github.com/rust-bakery/nom/tree/main/doc)\n- [List of combinators and their behaviour](https://github.com/rust-bakery/nom/blob/main/doc/choosing_a_combinator.md)\n\nIf you need any help developing your parsers, please ping `geal` on IRC (Libera, Geeknode, OFTC), go to `#nom-parsers` on Libera IRC, or on the [Gitter chat room](https://gitter.im/Geal/nom).\n\n## Why use nom\n\nIf you want to write:\n\n### Binary format parsers\n\nnom was designed to properly parse binary formats from the beginning. Compared\nto the usual handwritten C parsers, nom parsers are just as fast, free from\nbuffer overflow vulnerabilities, and handle common patterns for you:\n\n- [TLV](https://en.wikipedia.org/wiki/Type-length-value)\n- Bit level parsing\n- Hexadecimal viewer in the debugging macros for easy data analysis\n- Streaming parsers for network formats and huge files\n\nExample projects:\n\n- [FLV parser](https://github.com/rust-av/flavors)\n- [Matroska parser](https://github.com/rust-av/matroska)\n- [tar parser](https://github.com/Keruspe/tar-parser.rs)\n\n### Text format parsers\n\nWhile nom was made for binary format at first, it soon grew to work just as\nwell with text formats. From line based formats like CSV, to more complex, nested\nformats such as JSON, nom can manage it, and provides you with useful tools:\n\n- Fast case insensitive comparison\n- Recognizers for escaped strings\n- Regular expressions can be embedded in nom parsers to represent complex character patterns succinctly\n- Special care has been given to managing non ASCII characters properly\n\nExample projects:\n\n- [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/main/lib/src/protocol/h2/parser.rs)\n- [TOML parser](https://github.com/joelself/tomllib)\n\n### Programming language parsers\n\nWhile programming language parsers are usually written manually for more\nflexibility and performance, nom can be (and has been successfully) used\nas a prototyping parser for a language.\n\nnom will get you started quickly with powerful custom error types, that you\ncan leverage with [nom_locate](https://github.com/fflorent/nom_locate) to\npinpoint the exact line and column of the error. No need for separate\ntokenizing, lexing and parsing phases: nom can automatically handle whitespace\nparsing, and construct an AST in place.\n\nExample projects:\n\n- [PHP VM](https://github.com/tagua-vm/parser)\n- [xshade shading language](https://github.com/xshade-lang/xshade)\n\n### Streaming formats\n\nWhile a lot of formats (and the code handling them) assume that they can fit\nthe complete data in memory, there are formats for which we only get a part\nof the data at once, like network formats, or huge files.\nnom has been designed for a correct behaviour with partial data: If there is\nnot enough data to decide, nom will tell you it needs more instead of silently\nreturning a wrong result. Whether your data comes entirely or in chunks, the\nresult should be the same.\n\nIt allows you to build powerful, deterministic state machines for your protocols.\n\nExample projects:\n\n- [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/main/lib/src/protocol/h2/parser.rs)\n- [Using nom with generators](https://github.com/rust-bakery/generator_nom)\n\n## Parser combinators\n\nParser combinators are an approach to parsers that is very different from\nsoftware like [lex](https://en.wikipedia.org/wiki/Lex_(software)) and\n[yacc](https://en.wikipedia.org/wiki/Yacc). Instead of writing the grammar\nin a separate file and generating the corresponding code, you use very\nsmall functions with very specific purpose, like \"take 5 bytes\", or\n\"recognize the word 'HTTP'\", and assemble them in meaningful patterns\nlike \"recognize 'HTTP', then a space, then a version\".\nThe resulting code is small, and looks like the grammar you would have\nwritten with other parser approaches.\n\nThis has a few advantages:\n\n- The parsers are small and easy to write\n- The parsers components are easy to reuse (if they're general enough, please add them to nom!)\n- The parsers components are easy to test separately (unit tests and property-based tests)\n- The parser combination code looks close to the grammar you would have written\n- You can build partial parsers, specific to the data you need at the moment, and ignore the rest\n\n## Technical features\n\nnom parsers are for:\n- [x] **byte-oriented**: The basic type is `\u0026[u8]` and parsers will work as much as possible on byte array slices (but are not limited to them)\n- [x] **bit-oriented**: nom can address a byte slice as a bit stream\n- [x] **string-oriented**: The same kind of combinators can apply on UTF-8 strings as well\n- [x] **zero-copy**: If a parser returns a subset of its input data, it will return a slice of that input, without copying\n- [x] **streaming**: nom can work on partial data and detect when it needs more data to produce a correct result\n- [x] **descriptive errors**: The parsers can aggregate a list of error codes with pointers to the incriminated input slice. Those error lists can be pattern matched to provide useful messages.\n- [x] **custom error types**: You can provide a specific type to improve errors returned by parsers\n- [x] **safe parsing**: nom leverages Rust's safe memory handling and powerful types, and parsers are routinely fuzzed and tested with real world data. So far, the only flaws found by fuzzing were in code written outside of nom\n- [x] **speed**: Benchmarks have shown that nom parsers often outperform many parser combinators library like Parsec and attoparsec, some regular expression engines and even handwritten C parsers\n\nSome benchmarks are available on [GitHub](https://github.com/rust-bakery/parser_benchmarks).\n\n## Rust version requirements (MSRV)\n\nThe 8.0 series of nom supports **Rustc version 1.65 or greater**.\n\nThe current policy is that this will only be updated in the next major nom release.\n\n## Installation\n\nnom is available on [crates.io](https://crates.io/crates/nom) and can be included in your Cargo enabled project like this:\n\n```toml\n[dependencies]\nnom = \"8\"\n```\n\nThere are a few compilation features:\n\n* `alloc`: (activated by default) if disabled, nom can work in `no_std` builds without memory allocators. If enabled, combinators that allocate (like `many0`) will be available\n* `std`: (activated by default, activates `alloc` too) if disabled, nom can work in `no_std` builds\n\nYou can configure those features like this:\n\n```toml\n[dependencies.nom]\nversion = \"8\"\ndefault-features = false\nfeatures = [\"alloc\"]\n```\n\n# Related projects\n\n- [Get line and column info in nom's input type](https://github.com/fflorent/nom_locate)\n- [Using nom as lexer and parser](https://github.com/Rydgel/monkey-rust)\n\n# Parsers written with nom\n\nHere is a (non exhaustive) list of known projects using nom:\n\n- Text file formats: [Ceph Crush](https://github.com/cholcombe973/crushtool),\n[Cronenberg](https://github.com/ayrat555/cronenberg),\n[Email](https://github.com/deuxfleurs-org/eml-codec),\n[XFS Runtime Stats](https://github.com/ChrisMacNaughton/xfs-rs),\n[CSV](https://github.com/GuillaumeGomez/csv-parser),\n[FASTA](https://github.com/TianyiShi2001/nom-fasta),\n[FASTQ](https://github.com/elij/fastq.rs),\n[INI](https://github.com/rust-bakery/nom/blob/main/tests/ini.rs),\n[ISO 8601 dates](https://github.com/badboy/iso8601),\n[libconfig-like configuration file format](https://github.com/filipegoncalves/rust-config),\n[Web archive](https://github.com/sbeckeriv/warc_nom_parser),\n[PDB](https://github.com/TianyiShi2001/nom-pdb),\n[proto files](https://github.com/tafia/protobuf-parser),\n[Fountain screenplay markup](https://github.com/adamchalmers/fountain-rs),\n[vimwiki](https://github.com/chipsenkbeil/vimwiki-rs/tree/master/vimwiki), [vimwiki_macros](https://github.com/chipsenkbeil/vimwiki-rs/tree/master/vimwiki_macros),\n[Kconfig language](https://github.com/Mcdostone/nom-kconfig), [Askama templates](https://crates.io/crates/askama_parser/), [LP files](https://github.com/dandxy89/lp_parser_rs)\n- Programming languages:\n[PHP](https://github.com/tagua-vm/parser),\n[Basic Calculator](https://github.com/balajisivaraman/basic_calculator_rs),\n[GLSL](https://sr.ht/~hadronized/glsl)\n[Lua](https://github.com/rozbb/nom-lua53),\n[Python](https://github.com/ProgVal/rust-python-parser),\n[SQL](https://github.com/ms705/nom-sql),\n[Elm](https://github.com/cout970/Elm-interpreter),\n[SystemVerilog](https://github.com/dalance/sv-parser),\n[Turtle](https://github.com/vandenoever/rome/tree/master/src/io/turtle),\n[CSML](https://github.com/CSML-by-Clevy/csml-engine/tree/dev/csml_interpreter),\n[Wasm](https://github.com/fabrizio-m/wasm-nom),\n[Pseudocode](https://github.com/Gungy2/pseudocod),\n[Filter for MeiliSearch](https://github.com/meilisearch/meilisearch),\n[PotterScript](https://github.com/fmiras/potterscript),\n[R](https://github.com/kpagacz/tergo)\n- Interface definition formats: [Thrift](https://github.com/thehydroimpulse/thrust)\n- Audio, video and image formats:\n[GIF](https://github.com/Geal/gif.rs),\n[MagicaVoxel .vox](https://github.com/dust-engine/dot_vox),\n[MIDI](https://github.com/derekdreery/nom-midi-rs),\n[SWF](https://github.com/open-flash/swf-parser),\n[WAVE](https://github.com/Noise-Labs/wave),\n[Matroska (MKV)](https://github.com/rust-av/matroska),\n[Exif/Metadata parser for JPEG/HEIF/HEIC/MOV/MP4](https://github.com/mindeng/nom-exif)\n- Document formats:\n[TAR](https://github.com/Keruspe/tar-parser.rs),\n[GZ](https://github.com/nharward/nom-gzip),\n[GDSII](https://github.com/erihsu/gds2-io)\n- Cryptographic formats:\n[X.509](https://github.com/rusticata/x509-parser)\n- Network protocol formats:\n[Bencode](https://github.com/jbaum98/bencode.rs),\n[D-Bus](https://github.com/toshokan/misato),\n[DHCP](https://github.com/rusticata/dhcp-parser),\n[HTTP](https://github.com/sozu-proxy/sozu/tree/main/lib/src/protocol/http),\n[URI](https://github.com/santifa/rrp/blob/master/src/uri.rs),\n[IMAP](https://github.com/djc/tokio-imap) ([alt](https://github.com/duesee/imap-codec)),\n[IRC](https://github.com/Detegr/RBot-parser),\n[Pcap-NG](https://github.com/richo/pcapng-rs),\n[Pcap](https://github.com/ithinuel/pcap-rs),\n[Pcap + PcapNG](https://github.com/rusticata/pcap-parser),\n[IKEv2](https://github.com/rusticata/ipsec-parser),\n[NTP](https://github.com/rusticata/ntp-parser),\n[SNMP](https://github.com/rusticata/snmp-parser),\n[Kerberos v5](https://github.com/rusticata/kerberos-parser),\n[DER](https://github.com/rusticata/der-parser),\n[TLS](https://github.com/rusticata/tls-parser),\n[V5, V7, V9, IPFIX / Netflow v10](https://github.com/mikemiles-dev/netflow_parser),\n[GTP](https://github.com/fuerstenau/gorrosion-gtp),\n[SIP](https://github.com/kurotych/sipcore/tree/master/crates/sipmsg),\n[SMTP](https://github.com/Ekleog/kannader),\n[Prometheus](https://github.com/vectordotdev/vector/blob/master/lib/prometheus-parser/src/line.rs),\n[DNS](https://github.com/adiSuper94/dns-rs)\n- Language specifications:\n[BNF](https://github.com/shnewto/bnf)\n- Misc formats:\n[Game Boy ROM](https://github.com/MarkMcCaskey/gameboy-rom-parser),\n[ANT FIT](https://github.com/stadelmanma/fitparse-rs),\n[Version Numbers](https://github.com/fosskers/rs-versions),\n[Telcordia/Bellcore SR-4731 SOR OTDR files](https://github.com/JamesHarrison/otdrs),\n[MySQL binary log](https://github.com/PrivateRookie/boxercrab),\n[URI](https://github.com/Skasselbard/nom-uri),\n[Furigana](https://github.com/sachaarbonel/furigana.rs),\n[Wordle Result](https://github.com/Fyko/wordle-stats/tree/main/parser),\n[NBT](https://github.com/phoenixr-codes/mcnbt)\n\nWant to create a new parser using `nom`? A list of not yet implemented formats is available [here](https://github.com/rust-bakery/nom/issues/14).\n\nWant to add your parser here? Create a pull request for it!\n\n# Contributors\n\nnom is the fruit of the work of many contributors over the years, many thanks for your help!\n\n\u003ca href=\"https://github.com/rust-bakery/nom/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contributors-img.web.app/image?repo=rust-bakery/nom\" /\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":["Rust","Libraries","Language specific libraries","Rust 程序设计","rust","\u003ca name=\"Rust\"\u003e\u003c/a\u003eRust","虚拟化"],"sub_categories":["Parsing","Other dialects and variants","网络服务_其他","解析"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-bakery%2Fnom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom/lists"}