{"id":13439937,"url":"https://github.com/kevinmehall/rust-peg","last_synced_at":"2025-05-13T23:05:22.616Z","repository":{"id":387322,"uuid":"12204606","full_name":"kevinmehall/rust-peg","owner":"kevinmehall","description":"Parsing Expression Grammar (PEG) parser generator for Rust","archived":false,"fork":false,"pushed_at":"2025-03-11T14:26:03.000Z","size":1221,"stargazers_count":1524,"open_issues_count":41,"forks_count":109,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-10T03:50:52.430Z","etag":null,"topics":["grammar","parser-generator","parsing","parsing-expression-grammars","peg","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/peg","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/kevinmehall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2013-08-19T01:18:13.000Z","updated_at":"2025-05-07T20:53:11.000Z","dependencies_parsed_at":"2024-06-03T01:05:28.200Z","dependency_job_id":"717969a7-408b-48c2-8ea2-4a2e2f059e4f","html_url":"https://github.com/kevinmehall/rust-peg","commit_stats":{"total_commits":483,"total_committers":50,"mean_commits":9.66,"dds":"0.21118012422360244","last_synced_commit":"df9b0caf6c9696f233bc6ea4e78afd893ec7ab02"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmehall%2Frust-peg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmehall%2Frust-peg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmehall%2Frust-peg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmehall%2Frust-peg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinmehall","download_url":"https://codeload.github.com/kevinmehall/rust-peg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254040664,"owners_count":22004590,"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":["grammar","parser-generator","parsing","parsing-expression-grammars","peg","rust"],"created_at":"2024-07-31T03:01:18.321Z","updated_at":"2025-05-13T23:05:17.604Z","avatar_url":"https://github.com/kevinmehall.png","language":"Rust","funding_links":[],"categories":["Libraries","Rust","库 Libraries","库","Tools and Frameworks"],"sub_categories":["Parsing","Parser","解析 Parsing","解析","Other dialects and variants","Rust"],"readme":"# Parsing Expression Grammars in Rust\n\n[Documentation](https://docs.rs/peg) | [Release Notes](https://github.com/kevinmehall/rust-peg/releases)\n\n`rust-peg` is a simple yet flexible parser generator that makes it easy to write robust parsers. Based on the [Parsing Expression Grammar](https://en.wikipedia.org/wiki/Parsing_expression_grammar) formalism, it provides a Rust macro that builds a recursive descent parser from a concise definition of the grammar.\n\n## Features\n\n* Parse input from `\u0026str`, `\u0026[u8]`, `\u0026[T]` or custom types implementing traits\n* Customizable reporting of parse errors\n* Rules can accept arguments to create reusable rule templates\n* Precedence climbing for prefix/postfix/infix expressions\n* Helpful `rustc` error messages for errors in the grammar definition or the Rust\n  code embedded within it\n* Rule-level tracing to debug grammars\n\n## Example\n\nParse a comma-separated list of numbers surrounded by brackets into a `Vec\u003cu32\u003e`:\n\n```rust\npeg::parser!{\n  grammar list_parser() for str {\n    rule number() -\u003e u32\n      = n:$(['0'..='9']+) {? n.parse().or(Err(\"u32\")) }\n\n    pub rule list() -\u003e Vec\u003cu32\u003e\n      = \"[\" l:(number() ** \",\") \"]\" { l }\n  }\n}\n\npub fn main() {\n    assert_eq!(list_parser::list(\"[1,1,2,3,5,8]\"), Ok(vec![1, 1, 2, 3, 5, 8]));\n}\n```\n\n[See the tests for more examples](./tests/run-pass/)  \n[Grammar rule syntax reference in rustdoc](https://docs.rs/peg)\n\n## Comparison with similar parser generators\n\n| crate     \t| parser type \t| action code \t| integration        \t| input type             \t| precedence climbing \t| parameterized rules \t| streaming input \t|\n|-----------\t|-------------\t|-------------\t|--------------------\t|------------------------\t|---------------------\t|--------------------\t|-----------------\t|\n| peg       \t| PEG         \t| in grammar  \t| proc macro (block) \t| `\u0026str`, `\u0026[T]`, custom \t| Yes                 \t| Yes                \t| No              \t|\n| [pest]    \t| PEG         \t| external    \t| proc macro (file)  \t| `\u0026str`                 \t| Yes                 \t| No                 \t| No              \t|\n| [nom]     \t| combinators \t| in source   \t| library            \t| `\u0026[u8]`, custom        \t| No                  \t| Yes                \t| Yes             \t|\n| [lalrpop] \t| LR(1)       \t| in grammar  \t| build script       \t| `\u0026str`                 \t| No                  \t| Yes                \t| No              \t|\n\n[pest]: https://github.com/pest-parser/pest\n[nom]: https://github.com/geal/nom\n[lalrpop]: https://github.com/lalrpop/lalrpop\n\n## See also\n\n* [pegviz] is a UI for visualizing rust-peg's trace output to debug parsers.\n* There exist several crates to format diagnostic messages on source code snippets in the terminal, including [chic], [annotate-snippets], [codespan-reporting], and [codemap-diagnostic].\n\n[pegviz]: https://github.com/fasterthanlime/pegviz\n[chic]: https://crates.io/crates/chic\n[annotate-snippets]: https://crates.io/crates/annotate-snippets\n[codespan-reporting]: https://crates.io/crates/codespan-reporting\n[codemap-diagnostic]: https://crates.io/crates/codemap-diagnostic\n\n## Development\n\nThe `rust-peg` grammar is written in `rust-peg`: `peg-macros/grammar.rustpeg`. To avoid the circular dependency, a precompiled grammar is checked in as `peg-macros/grammar.rs`. To regenerate this, run the `./bootstrap.sh` script.\n\nThere is a large test suite which uses [`trybuild`](https://crates.io/crates/trybuild) to test both functionality (`tests/run-pass`) and error messages for incorrect grammars (`tests/compile-fail`). Because `rustc` error messages change, the `compile-fail` tests are only run on the minimum supported Rust version to avoid spurious failures.\n\nUse `cargo test` to run the entire suite,\nor `cargo test -- trybuild trybuild=lifetimes.rs` to test just the indicated file.\nAdd `--features trace` to trace these tests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmehall%2Frust-peg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinmehall%2Frust-peg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmehall%2Frust-peg/lists"}