Need help with chomp?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

203 Stars 15 Forks Other 394 Commits 20 Opened issues


A fast monadic-style parser combinator designed to work on stable Rust.

Services available


Need anything else?

Contributors list

No Data


Gitter Build Status Coverage Status Documentation

Chomp is a fast monadic-style parser combinator library designed to work on stable Rust. It was written as the culmination of the experiments detailed in these blog posts:

For its current capabilities, you will find that Chomp performs consistently as well, if not better, than optimized C parsers, while being vastly more expressive. For an example that builds a performant HTTP parser out of smaller parsers, see


Add the following line to the dependencies section of your

chomp = "0.3.1"


Parsers are functions from a slice over an input type

to a
, which may be thought of as either a success resulting in type
, an error of type
, or a partially completed result which may still consume more input of type

The input type is almost never manually manipulated. Rather, one uses parsers from Chomp by invoking the

macro. This macro was designed intentionally to be as close as possible to Haskell's
-syntax or F#'s "computation expressions", which are used to sequence monadic computations. At a very high level, usage of this macro allows one to declaratively:
  • Sequence parsers, while short circuiting the rest of the parser if any step fails.
  • Bind previous successful results to be used later in the computation.
  • Return a composite datastructure using the previous results at the end of the computation.

In other words, just as a normal Rust function usually looks something like this:

fn f() -> (u8, u8, u8) {
    let a = read_digit();
    let b = read_digit();
    return (a, b, a + b);

A Chomp parser with a similar structure looks like this:

fn f(i: I) -> SimpleResult {
        let a = digit();
        let b = digit();
        ret (a, b, a + b)

And to implement

we can utilize the
function to manipulate any success value while preserving any error or incomplete state:
// Standard rust, no error handling:
fn read_digit() -> u8 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();

// Chomp, error handling built in, and we make sure we only get a number: fn read_digit<i: u8input>(i: I) -> SimpleResult { satisfy(i, |c| b'0' <= c && c <= b'9').map(|c| c - b'0') }

For more documentation, see the rust-doc output.


extern crate chomp;

use chomp::prelude::*;

#[derive(Debug, Eq, PartialEq)] struct Name<b: buffer> { first: B, last: B, }

fn name<i: u8input>(i: I) -> SimpleResult> { parse!{i; let first = take_while1(|c| c != b' '); token(b' '); // skipping this char let last = take_while1(|c| c != b'\n');

    ret Name{
        first: first,
        last:  last,


assert_eq!(parse_only(name, "Martin Wernstål\n".as_bytes()), Ok(Name{ first: &b"Martin"[..], last: "Wernstål".as_bytes() }));


Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or
  • MIT license (LICENSE-MIT or

at your option.


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.


File an issue here on Github or visit

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.