{"id":24756325,"url":"https://github.com/dalance/nom-greedyerror","last_synced_at":"2025-11-11T11:19:29.185Z","repository":{"id":52400607,"uuid":"215446119","full_name":"dalance/nom-greedyerror","owner":"dalance","description":"Custom error type of nom to improve accuracy of error position","archived":false,"fork":false,"pushed_at":"2023-03-23T00:26:31.000Z","size":22,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T05:45:38.488Z","etag":null,"topics":["nom","rust","rust-library"],"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/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}},"created_at":"2019-10-16T03:11:10.000Z","updated_at":"2024-12-22T08:17:22.000Z","dependencies_parsed_at":"2022-09-08T16:41:40.313Z","dependency_job_id":"51103ee3-de5f-4901-a9af-0d4d673eaf38","html_url":"https://github.com/dalance/nom-greedyerror","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"1ee35113c549439a82932cb9de0d7a228eacb592"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/dalance/nom-greedyerror","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-greedyerror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-greedyerror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-greedyerror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-greedyerror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dalance","download_url":"https://codeload.github.com/dalance/nom-greedyerror/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-greedyerror/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264837310,"owners_count":23671012,"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":["nom","rust","rust-library"],"created_at":"2025-01-28T13:50:50.227Z","updated_at":"2025-11-11T11:19:29.120Z","avatar_url":"https://github.com/dalance.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nom-greedyerror\nCustom error type of [nom](https://github.com/Geal/nom) to improve accuracy of error position.\n\n[![Actions Status](https://github.com/dalance/nom-greedyerror/workflows/Rust/badge.svg)](https://github.com/dalance/nom-greedyerror/actions)\n[![Crates.io](https://img.shields.io/crates/v/nom-greedyerror.svg)](https://crates.io/crates/nom-greedyerror)\n[![Docs.rs](https://docs.rs/nom-greedyerror/badge.svg)](https://docs.rs/nom-greedyerror)\n\nThe default error types of nom ( `(I, ErrorKind)` and `VerboseError` ) take a last challenged error at `alt` combinator.\nAlternatively `GreedyError` of nom-greedyerror take a deepest error.\n\nFor example, the following parser accepts string like `abc012abc` or `012abc012`.\n\n```rust\nalt((\n    tuple((alpha1, digit1, alpha1)),\n    tuple((digit1, alpha1, digit1)),\n))(input)\n```\n\nIf `abc012:::` is provided, we expect that the parse error happens at:\n\n```\nabc012:::\n      ^\n```\n\nBut `VerboseError` reports the parse error at:\n\n```\nabc012:::\n^\n```\n\nThis is because the last challenged parser is `tuple((digit1, alpha1, digit1))` and it is failed.\n`GreedyError` reports the parse error at the expected position.\n\n## Requirement\n\nnom must be 5.0.0 or later.\n\n## Usage\n\n```Cargo.toml\n[dependencies]\nnom-greedyerror = \"0.5.0\"\n```\n\n## Example\n\n```rust\nuse nom::branch::alt;\nuse nom::character::complete::{alpha1, digit1};\nuse nom::error::{ErrorKind, ParseError, VerboseError};\nuse nom::sequence::tuple;\nuse nom::Err::Error;\nuse nom::IResult;\nuse nom_greedyerror::{error_position, GreedyError, Position};\nuse nom_locate::LocatedSpan;\n\ntype Span\u003c'a\u003e = LocatedSpan\u003c\u0026'a str\u003e;\n\nfn parser\u003c'a, E: ParseError\u003cSpan\u003c'a\u003e\u003e\u003e(\n    input: Span\u003c'a\u003e,\n) -\u003e IResult\u003cSpan\u003c'a\u003e, (Span\u003c'a\u003e, Span\u003c'a\u003e, Span\u003c'a\u003e), E\u003e {\n    alt((\n        tuple((alpha1, digit1, alpha1)),\n        tuple((digit1, alpha1, digit1)),\n    ))(input)\n}\n\nfn main() {\n    // VerboseError failed at\n    //   abc012:::\n    //   ^\n    let error = parser::\u003cVerboseError\u003cSpan\u003e\u003e(Span::new(\"abc012:::\"));\n    dbg!(\u0026error);\n    match error {\n        Err(Error(e)) =\u003e assert_eq!(e.errors.first().map(|x| x.0.position()), Some(0)),\n        _ =\u003e (),\n    };\n\n    // GreedyError failed at\n    //   abc012:::\n    //         ^\n    let error = parser::\u003cGreedyError\u003cSpan, ErrorKind\u003e\u003e(Span::new(\"abc012:::\"));\n    dbg!(\u0026error);\n    match error {\n        Err(Error(e)) =\u003e assert_eq!(error_position(\u0026e), Some(6)),\n        _ =\u003e (),\n    };\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\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-greedyerror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalance%2Fnom-greedyerror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalance%2Fnom-greedyerror/lists"}