{"id":13822686,"url":"https://github.com/rust-bakery/nom-peg","last_synced_at":"2025-05-16T17:31:38.800Z","repository":{"id":50429450,"uuid":"180526457","full_name":"rust-bakery/nom-peg","owner":"rust-bakery","description":"PEG parser generator built on top of nom","archived":false,"fork":false,"pushed_at":"2019-09-02T18:33:37.000Z","size":35,"stargazers_count":67,"open_issues_count":3,"forks_count":6,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-09T18:54:07.711Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-bakery.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}},"created_at":"2019-04-10T07:27:35.000Z","updated_at":"2024-03-18T20:37:06.000Z","dependencies_parsed_at":"2022-08-26T05:51:18.162Z","dependency_job_id":null,"html_url":"https://github.com/rust-bakery/nom-peg","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-peg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-peg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-peg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-bakery%2Fnom-peg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-bakery","download_url":"https://codeload.github.com/rust-bakery/nom-peg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213893314,"owners_count":15653524,"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":[],"created_at":"2024-08-04T08:02:12.633Z","updated_at":"2024-08-04T08:08:51.997Z","avatar_url":"https://github.com/rust-bakery.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# PEG Grammars for Nom\n\nnom-peg is a PEG (Parsing Expression Grammar) parser generator built on top of [nom](https://github.com/Geal/nom), using a syntax that is heavily inspired by [LALRPOP](https://github.com/lalrpop/lalrpop).\n\nGrammars defined with nom-peg can freely be mixed with other nom parsers.\n\n## Example\n```rust\nlet arithmetic = grammar! {\n    // a grammar can have as many non-terminals as you want, and can return any type\n    parse: i64 = \u003cterm\u003e \"=\"\n\n    // alternatives are separated by `|`,\n    // and the `=\u003e { ... }` syntax is used to manipulate the output of the parser before returning it\n    term: i64 = \u003cl: factor\u003e \"+\" \u003cr: term\u003e =\u003e { l + r }\n              | \u003cl: factor\u003e \"-\" \u003cr: term\u003e =\u003e { l - r }\n              | factor\n\n    // the `\u003c...\u003e` syntax is used to capture the output of a sub-parser,\n    // and optionally assign it to a local variable with `\u003cname: ...\u003e`\n    factor: i64 = \u003cl: value\u003e \"*\" \u003cr: factor\u003e =\u003e { l * r }\n                | \u003cl: value\u003e \"/\" \u003cr: factor\u003e =\u003e { l / r }\n                | value\n\n    value: i64 = (\"0\"|\"1\"|\"2\"|\"3\"|\"4\"|\"5\"|\"6\"|\"7\"|\"8\"|\"9\")+ =\u003e { result.join(\"\").parse::\u003ci64\u003e().unwrap() }\n               | \"(\" \u003cterm\u003e \")\"\n};\n\n// when the grammar is defined you can use any of the non-terminals as parser functions\nassert_eq!(arithmetic.parse(\"123=\"), Ok((\"\", 123 as i64)));\nassert_eq!(arithmetic.parse(\"1+1=\"), Ok((\"\", 2 as i64)));\nassert_eq!(arithmetic.parse(\"12+(3*7)=\"), Ok((\"\", 33 as i64)));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom-peg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-bakery%2Fnom-peg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-bakery%2Fnom-peg/lists"}