{"id":13416013,"url":"https://github.com/m4rw3r/chomp","last_synced_at":"2025-08-02T11:39:15.219Z","repository":{"id":2322095,"uuid":"46239320","full_name":"m4rw3r/chomp","owner":"m4rw3r","description":"A fast monadic-style parser combinator designed to work on stable Rust.","archived":false,"fork":false,"pushed_at":"2022-05-11T12:47:57.000Z","size":7167,"stargazers_count":244,"open_issues_count":21,"forks_count":19,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-06T10:53:32.176Z","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/m4rw3r.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}},"created_at":"2015-11-15T22:42:46.000Z","updated_at":"2025-06-05T00:33:44.000Z","dependencies_parsed_at":"2022-08-08T22:30:11.998Z","dependency_job_id":null,"html_url":"https://github.com/m4rw3r/chomp","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/m4rw3r/chomp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4rw3r%2Fchomp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4rw3r%2Fchomp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4rw3r%2Fchomp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4rw3r%2Fchomp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m4rw3r","download_url":"https://codeload.github.com/m4rw3r/chomp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4rw3r%2Fchomp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268379680,"owners_count":24241095,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-07-30T21:00:53.653Z","updated_at":"2025-08-02T11:39:15.196Z","avatar_url":"https://github.com/m4rw3r.png","language":"Rust","readme":"# Chomp\n\n[![Gitter](https://badges.gitter.im/m4rw3r/chomp.svg)](https://gitter.im/m4rw3r/chomp?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n[![Build Status](https://travis-ci.org/m4rw3r/chomp.svg?branch=master)](https://travis-ci.org/m4rw3r/chomp)\n[![Coverage Status](https://coveralls.io/repos/m4rw3r/chomp/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/m4rw3r/chomp?branch=master)\n[![Crates.io](https://img.shields.io/crates/v/chomp.svg)](https://crates.io/crates/chomp)\n[![Documentation](https://img.shields.io/badge/rustdoc-documentation-blue.svg)](http://m4rw3r.github.io/chomp)\n\nChomp 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:\n\n* [Part 1](http://m4rw3r.github.io/parser-combinator-experiments-rust)\n* [Part 2](http://m4rw3r.github.io/parser-combinator-experiments-errors)\n* [Part 3](http://m4rw3r.github.io/parser-combinator-experiments-part-3)\n* [Chomp 0.1 Announcement](http://m4rw3r.github.io/parser-combinators-road-chomp-0-1)\n\nFor 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 [http_parser.rs](examples/http_parser.rs).\n\n## Installation\n\nAdd the following line to the dependencies section of your `Cargo.toml`:\n\n```toml\n[dependencies]\nchomp = \"0.3.1\"\n```\n\n## Usage\n\nParsers are functions from a slice over an input type `Input\u003cI\u003e` to a `ParseResult\u003cI, T, E\u003e`, which may be thought of as either a success resulting in type `T`, an error of type `E`, or a partially completed result which may still consume more input of type `I`.\n\nThe input type is almost never manually manipulated. Rather, one uses parsers from Chomp by invoking the `parse!` macro. This macro was designed intentionally to be as close as possible to Haskell's `do`-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:\n\n* Sequence parsers, while short circuiting the rest of the parser if any step fails.\n* Bind previous successful results to be used later in the computation.\n* Return a composite datastructure using the previous results at the end of the computation.\n\nIn other words, just as a normal Rust function usually looks something like this:\n\n```rust\nfn f() -\u003e (u8, u8, u8) {\n    let a = read_digit();\n    let b = read_digit();\n    launch_missiles();\n    return (a, b, a + b);\n}\n```\n\nA Chomp parser with a similar structure looks like this:\n\n```rust\nfn f\u003cI: U8Input\u003e(i: I) -\u003e SimpleResult\u003cI, (u8, u8, u8)\u003e {\n    parse!{i;\n        let a = digit();\n        let b = digit();\n                string(b\"missiles\");\n        ret (a, b, a + b)\n    }\n}\n```\n\nAnd to implement `read_digit` we can utilize the `map` function to manipulate any success value while preserving any error or incomplete state:\n\n```rust\n// Standard rust, no error handling:\nfn read_digit() -\u003e u8 {\n    let mut s = String::new();\n    std::io::stdin().read_line(\u0026mut s).unwrap();\n    s.trim().parse().unwrap()\n}\n\n// Chomp, error handling built in, and we make sure we only get a number:\nfn read_digit\u003cI: U8Input\u003e(i: I) -\u003e SimpleResult\u003cI, u8\u003e {\n    satisfy(i, |c| b'0' \u003c= c \u0026\u0026 c \u003c= b'9').map(|c| c - b'0')\n}\n```\n\nFor more documentation, see the rust-doc output.\n\n## Example\n\n```rust\n#[macro_use]\nextern crate chomp;\n\nuse chomp::prelude::*;\n\n#[derive(Debug, Eq, PartialEq)]\nstruct Name\u003cB: Buffer\u003e {\n    first: B,\n    last:  B,\n}\n\nfn name\u003cI: U8Input\u003e(i: I) -\u003e SimpleResult\u003cI, Name\u003cI::Buffer\u003e\u003e {\n    parse!{i;\n        let first = take_while1(|c| c != b' ');\n                    token(b' ');  // skipping this char\n        let last  = take_while1(|c| c != b'\\n');\n\n        ret Name{\n            first: first,\n            last:  last,\n        }\n    }\n}\n\nassert_eq!(parse_only(name, \"Martin Wernstål\\n\".as_bytes()), Ok(Name{\n    first: \u0026b\"Martin\"[..],\n    last: \"Wernstål\".as_bytes()\n}));\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([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 for inclusion in\nthe work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n\n## Contact\n\nFile an issue [here](https://github.com/m4rw3r/chomp/issues/new) on Github or visit [gitter.im/m4rw3r/chomp](https://gitter.im/m4rw3r/chomp).\n","funding_links":[],"categories":["Libraries","库 Libraries","库","Rust"],"sub_categories":["Parsing","Parser","解析 Parsing","解析","Other dialects and variants"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4rw3r%2Fchomp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm4rw3r%2Fchomp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4rw3r%2Fchomp/lists"}