{"id":24756335,"url":"https://github.com/dalance/nom-both","last_synced_at":"2025-08-01T06:07:29.255Z","repository":{"id":57645490,"uuid":"199366607","full_name":"dalance/nom-both","owner":"dalance","description":null,"archived":false,"fork":false,"pushed_at":"2019-07-29T10:39:38.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-07T18:23:20.303Z","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":"other","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}},"created_at":"2019-07-29T02:50:29.000Z","updated_at":"2019-07-29T10:39:36.000Z","dependencies_parsed_at":"2022-08-30T08:11:38.927Z","dependency_job_id":null,"html_url":"https://github.com/dalance/nom-both","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dalance/nom-both","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-both","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-both/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-both/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-both/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dalance","download_url":"https://codeload.github.com/dalance/nom-both/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalance%2Fnom-both/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268177814,"owners_count":24208396,"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-01T02:00:08.611Z","response_time":67,"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":"2025-01-28T13:50:53.960Z","updated_at":"2025-08-01T06:07:29.220Z","avatar_url":"https://github.com/dalance.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nom-both\nExtension of [nom](https://github.com/Geal/nom) to provide special `both_` parsers.\n\n[![Build Status](https://dev.azure.com/dalance/nom-both/_apis/build/status/dalance.nom-both?branchName=master)](https://dev.azure.com/dalance/nom-both/_build/latest?definitionId=1\u0026branchName=master)\n[![Crates.io](https://img.shields.io/crates/v/nom-both.svg)](https://crates.io/crates/nom-both)\n[![Docs.rs](https://docs.rs/nom-both/badge.svg)](https://docs.rs/nom-both)\n\n## Requirement\n\nnom must be 5.0.0 or later.\nnom-both can be applied to function-style parser only.\n\n## Usage\n\n```Cargo.toml\n[dependencies]\nnom-both = \"0.1.1\"\n```\n\n## Example\n\nnom-both provide `both_opt` and `both_alt` parser.\n`both_opt` means that the parser tries both argument parser and skip.\n`both_alt` means that the parser tries both 1st argument parser and 2nd argument parser.\n\n```rust\nuse nom::branch::*;\nuse nom::bytes::complete::*;\nuse nom::IResult;\nuse nom_both::both_parser;\n\n#[both_parser]\npub fn both_opt_parser(s: \u0026str) -\u003e IResult\u003c\u0026str, Option\u003c\u0026str\u003e\u003e {\n    let (s, _) = tag(\"1\")(s)?;\n    let (s, x) = both_opt(tag(\"2\"))(s)?;\n    let (s, _) = tag(\"2\")(s)?;\n    let (s, _) = tag(\"3\")(s)?;\n    Ok((s, x))\n}\n\n#[both_parser]\npub fn both_alt_parser(s: \u0026str) -\u003e IResult\u003c\u0026str, \u0026str\u003e {\n    let (s, _) = tag(\"1\")(s)?;\n    let (s, x) = both_alt(tag(\"22\"), tag(\"2\"))(s)?;\n    let (s, _) = tag(\"2\")(s)?;\n    let (s, _) = tag(\"3\")(s)?;\n    Ok((s, x))\n}\n\n#[test]\nfn test() {\n    let ret = both_opt_parser(\"123\");\n    assert_eq!(\"None\", format!(\"{:?}\", ret.unwrap().1));\n\n    let ret = both_alt_parser(\"1223\");\n    assert_eq!(\"\\\"2\\\"\", format!(\"{:?}\", ret.unwrap().1));\n}\n```\n\n`both_opt_parser` is expanded as below:\n\n```rust\npub fn both_opt_parser(s: \u0026str) -\u003e IResult\u003c\u0026str, Option\u003c\u0026str\u003e\u003e {\n    alt((\n        { |s| {\n            let (s, _) = tag(\"1\")(s)?;\n            let (s, x) = nom_both::some(tag(\"2\"))(s)?;\n            let (s, _) = tag(\"2\")(s)?;\n            let (s, _) = tag(\"3\")(s)?;\n            Ok((s, x))\n        } },\n        { |s| {\n            let (s, _) = tag(\"1\")(s)?;\n            let (s, x) = nom_both::none(tag(\"2\"))(s)?;\n            let (s, _) = tag(\"2\")(s)?;\n            let (s, _) = tag(\"3\")(s)?;\n            Ok((s, x))\n        } },\n    ))(s)\n}\n```\n\n`both_alt_parser` is expanded as below:\n\n```rust\npub fn both_opt_parser(s: \u0026str) -\u003e IResult\u003c\u0026str, Option\u003c\u0026str\u003e\u003e {\n    alt((\n        { |s| {\n            let (s, _) = tag(\"1\")(s)?;\n            let (s, x) = nom_both::alt_left(tag(\"22\"), tag(\"2\"))(s)?;\n            let (s, _) = tag(\"2\")(s)?;\n            let (s, _) = tag(\"3\")(s)?;\n            Ok((s, x))\n        } },\n        { |s| {\n            let (s, _) = tag(\"1\")(s)?;\n            let (s, x) = nom_both::alt_right(tag(\"22\"), tag(\"2\"))(s)?;\n            let (s, _) = tag(\"2\")(s)?;\n            let (s, _) = tag(\"3\")(s)?;\n            Ok((s, x))\n        } },\n    ))(s)\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-both","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalance%2Fnom-both","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalance%2Fnom-both/lists"}