{"id":24756330,"url":"https://github.com/dalance/nom-packrat","last_synced_at":"2025-11-11T11:30:38.364Z","repository":{"id":47454719,"uuid":"198135463","full_name":"dalance/nom-packrat","owner":"dalance","description":"Extension of nom to apply \"Packrat Parsing\"","archived":false,"fork":false,"pushed_at":"2025-02-03T20:14:31.000Z","size":75,"stargazers_count":21,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T18:22:04.607Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dalance.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-22T02:53:09.000Z","updated_at":"2023-07-16T21:53:10.000Z","dependencies_parsed_at":"2025-02-28T08:41:59.186Z","dependency_job_id":"0c700ad9-2080-49dd-a9c2-adc54aba50dd","html_url":"https://github.com/dalance/nom-packrat","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-packrat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-packrat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-packrat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-packrat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dalance","download_url":"https://codeload.github.com/dalance/nom-packrat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767236,"owners_count":20992548,"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":"2025-01-28T13:50:52.229Z","updated_at":"2025-11-11T11:30:38.318Z","avatar_url":"https://github.com/dalance.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nom-packrat\nExtension of [nom](https://github.com/Geal/nom) to apply [\"Packrat Parsing\"](https://en.wikipedia.org/wiki/Parsing_expression_grammar#Implementing_parsers_from_parsing_expression_grammars).\n\n[![Actions Status](https://github.com/dalance/nom-packrat/workflows/Regression/badge.svg)](https://github.com/dalance/nom-packrat/actions)\n[![Crates.io](https://img.shields.io/crates/v/nom-packrat.svg)](https://crates.io/crates/nom-packrat)\n[![Docs.rs](https://docs.rs/nom-packrat/badge.svg)](https://docs.rs/nom-packrat)\n\n## Requirement\n\nnom must be 5.0.0 or later.\nnom-packrat can be applied to function-style parser only.\n\n## Usage\n\n```Cargo.toml\n[dependencies]\nnom-packrat = \"0.7.0\"\n```\n\n## Example\n\n```rust\nuse nom::character::complete::char;\nuse nom::IResult;\nuse nom_packrat::{init, packrat_parser, storage};\n\n// Declare storage used by packrat_parser\nstorage!(String);\n\n// Apply packrat_parser by custom attribute\n#[packrat_parser]\npub fn parser(s: \u0026str) -\u003e IResult\u003c\u0026str, String\u003e {\n    let (s, x) = char('a')(s)?;\n    Ok((s, x.to_string()))\n}\n\nfn main() {\n    let input = \"a\";\n\n    // Initialize before parsing\n    init!();\n    let result = parser(input);\n\n    println!(\"{:?}\", result);\n}\n```\n\n## Performance\n\n### Syntax\n\n```\n\u003cS\u003e ::= \u003cT\u003e + \u003cS\u003e | \u003cT\u003e - \u003cS\u003e | \u003cT\u003e\n\u003cT\u003e ::= ( \u003cS\u003e ) | a\n```\n\n### Input\n\nThe following 8 patterns.\nThe first pattern is named as \"pair 0\" and the last is \"pair 7\".\n\n```\na\n(a)\n((a))\n(((a)))\n((((a))))\n(((((a)))))\n((((((a))))))\n(((((((a)))))))\n```\n\n### Result\n\n * original   : the original nom parser\n * packrat    : all parsers with `#[packrat_parser]`\n * packrat_opt: only `\u003cT\u003e` with `#[packrat_parser]`\n\nThis is an edge case. The execution time of the original parser increases exponentially.\nBy packrat pasring, the time becomes linear.\nInstead packrat parsers consume more memory than the original parser.\n\n![speed](https://user-images.githubusercontent.com/4331004/61628860-6634a280-acbe-11e9-9e7b-abbc75bef355.png)\n\n![memory](https://user-images.githubusercontent.com/4331004/61628911-7ba9cc80-acbe-11e9-9306-d1cc24f4a126.png)\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\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms or\nconditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalance%2Fnom-packrat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalance%2Fnom-packrat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalance%2Fnom-packrat/lists"}