Skip to content

nom

A Rust library for building fast, safe parsers by combining small parsing functions.

Stars
10.5k
Forks
848
Licence
MIT
Language
Rust
Last update
1.2 years ago
Type
Library

No commits in over a year — check for forks or alternatives before adopting.

What it is

nom is a parser combinators library written in Rust. You build parsers by assembling small functions, such as 'take 5 bytes' or 'recognize the word HTTP', into larger patterns that look like the grammar they describe. It is designed for reading binary formats, text formats, and streaming data without copying input unnecessarily.

  • Parse a hexadecimal color such as #2F14DF into its red, green, and blue values, as shown in the README example
  • Write parsers for binary formats like TLV structures or bit-level data
  • Parse text formats such as CSV, JSON, or TOML
  • Build streaming parsers that report when they need more data before producing a result

Great for

  • Rust developers writing parsers for binary or text file formats
  • Developers parsing network protocols or data that arrives in chunks
  • Engineers prototyping a parser for a programming language or data format
  • Developers who want parsers that are small, testable, and reusable

Not ideal for

  • People who are not writing Rust code, since this is a Rust-only library
  • Projects needing a ready-made tool that reads a grammar file and generates a parser, since nom is code you write by hand with combinators
  • Beginners new to Rust, because the README's examples rely on Rust's type system and error handling
Step-by-step guide: how to use nomInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Rust toolchain (rustc 1.65.0 or newer, per the README badge and MSRV section)

    Add nom to a Rust project

    cargo add nom
  2. 2

    Run it

    • Add nom to your Cargo project with cargo add nom
    • Copy the hexadecimal color example from the README into src/main.rs
    • Run it with cargo run to see the parsed color printed
    • Run cargo test to check the included parse_color test
  3. 3

    Get the most out of it

    • Read the Nominomicon guide linked in the README for a structured introduction
    • Use the combinator list in doc/choosing_a_combinator.md to pick the right building blocks
    • Add nom_locate, which the README mentions, to report exact line and column positions in errors
    • Use the streaming mode when your input arrives in chunks or comes from a network connection

Downloads

Strengths

  • The README says it is designed to be fast and memory-safe, with benchmarks it reports as competitive with several other parser libraries and handwritten C parsers
  • Parsers are assembled from small reusable pieces that are easy to test separately
  • Error reporting can aggregate error codes and custom error types

Trade-offs

  • You write parsers in Rust code with combinator functions, which takes learning before it feels natural
  • The README's documentation links point to external resources such as a guide and reference docs, so getting started depends on them
  • The README notes a minimum Rust version of 1.65 and the latest series is referred to as 8.0, so check compatibility with your toolchain

How it compares

ProjectStarsTypeLevelUpdatedBest for
nom (this)10.5kLibraryintermediate1.2 years agoRust developers writing parsers for binary or text file formats
pest11.8kLibraryintermediate4 days agoPHP developers who want to add automated tests to a project
cheerio30.5kLibrarybeginner4 days agoJavaScript developers who already know jQuery-style selectors
tree-sitter27.4kLibraryadvanced4 days agoDevelopers building code editors or IDE features that need to understand source code as it changes
parsedown15kLibrarybeginner9 months agoPHP developers who need to render Markdown inside a PHP web application
go13.9kLibrarybeginner2.4 years agoGo developers who parse or produce large amounts of JSON and want to test a faster option

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.