{"id":16244062,"url":"https://github.com/doumanash/banjin","last_synced_at":"2025-07-24T13:04:37.538Z","repository":{"id":62438511,"uuid":"160377676","full_name":"DoumanAsh/banjin","owner":"DoumanAsh","description":"Simple code generator for string parsing","archived":false,"fork":false,"pushed_at":"2018-12-15T14:03:18.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T17:50:36.353Z","etag":null,"topics":["parser"],"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/DoumanAsh.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":"2018-12-04T15:21:25.000Z","updated_at":"2019-04-29T07:51:32.000Z","dependencies_parsed_at":"2022-11-01T21:47:12.306Z","dependency_job_id":null,"html_url":"https://github.com/DoumanAsh/banjin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoumanAsh%2Fbanjin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoumanAsh%2Fbanjin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoumanAsh%2Fbanjin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoumanAsh%2Fbanjin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DoumanAsh","download_url":"https://codeload.github.com/DoumanAsh/banjin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829517,"owners_count":21002997,"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":["parser"],"created_at":"2024-10-10T14:17:40.028Z","updated_at":"2025-04-08T11:18:38.712Z","avatar_url":"https://github.com/DoumanAsh.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# banjin\n\n[![Build Status](https://travis-ci.org/DoumanAsh/banjin.svg?branch=master)](https://travis-ci.org/DoumanAsh/banjin)\n[![Crates.io](https://img.shields.io/crates/v/banjin.svg)](https://crates.io/crates/banjin)\n[![Documentation](https://docs.rs/banjin/badge.svg)](https://docs.rs/crate/banjin/)\n[![dependency status](https://deps.rs/repo/github/DoumanAsh/banjin/status.svg)](https://deps.rs/repo/github/DoumanAsh/banjin)\n\nSimple code generator for manual parsing\n\n## Attributes\n\n### Struct\n\nThere are several attributes that control behaviour of parser\nEach, attached to struct's field\n\n- `starts_with = \u003cprefix\u003e` - Specifies string with which next parse step should start(can be stacked). Errors if prefix is missing.\n- `ends_with = \u003cprefix\u003e` - Specifies string with which parse step should end(can be stacked). Errors if suffix is missing. If empty, expects EOF.\n- `skip = \u003cchars\u003e` - Specifies to skip characters, until not meeting character outside of specified in string.\n- `skip(ws)` - Specifies to skip all white space characters.\n- `format(\u003cformat\u003e)` - Specifies list of characters that should contain value to parse from.\n- `format(not(\u003cformat\u003e))` - Specifies list of characters that should contain value to parse from.\n\n##### Formats\n\n- Literal string - When string is specified as argument to `format`, it is used as set of characters.\n- `numeric` - When specified, match using `char::is_numeric()`\n- `digit(\u003cbase\u003e)` - When specified, match using `char::is_digit(\u003cbase\u003e)`\n- `ascii` - When specified, match using `char::is_ascii()`\n- `alphabetic` - When specified, match using `char::is_alphabetic()`\n\n### Enum\n\n- `format = \u003cformat\u003e` - Specifies string to match against.\n- `case` - Specifies case sensitive match. By default it is insensitive.\n- `default` - Specifies variant as taking default value. Should take only single `String` and\nthere can be only one\n\n## Usage\n\n### Struct\n\n```rust\nuse std::str::FromStr;\n\n#[derive(banjin::Parser)]\npub struct Data {\n    #[starts_with = \"prefix\"]\n    #[skip(ws)]\n    #[starts_with = \"+\"]\n    #[skip(ws)]\n    #[format(ascii)]\n    #[format(digit(10))]\n    pub first: u32,\n    #[skip(ws)]\n    #[format(not(\"d\"))]\n    #[format(\"13\")]\n    #[ends_with = \"d\"]\n    #[ends_with = \"\"]\n    pub second: String,\n}\n\nfn main() {\n    let data = Data::from_str(\"prefix + 666   13d\").expect(\"Parse\");\n    assert_eq!(data.first, 666);\n    assert_eq!(data.second, \"13\");\n\n    let data = Data::from_str(\"prefix + 666   13\");\n    assert!(data.is_err());\n\n    let data = Data::from_str(\"prefix 666   13d\");\n    assert!(data.is_err());\n\n    let data = Data::from_str(\"prefix + 666   13dg\");\n    assert!(data.is_err());\n\n    let data = Data::from_str(\"\");\n    assert!(data.is_err());\n}\n\n```\n\n### Enum\n\n```rust\nuse std::str::FromStr;\n\n#[derive(banjin::Parser, PartialEq, Eq, Debug)]\nenum Gender {\n    Male,\n    #[case]\n    Female,\n    #[default]\n    Other(String)\n}\n\nfn main() {\n    let gender = Gender::from_str(\"male\").expect(\"Parse\");\n    assert_eq!(gender, Gender::Male);\n\n    let gender = Gender::from_str(\"female\").expect(\"Parse\");\n    match gender {\n        Gender::Other(text) =\u003e assert_eq!(text, \"female\"),\n        _ =\u003e panic!(\"Unexpected!\")\n    }\n\n    let gender = Gender::from_str(\"none\").expect(\"Parse\");\n    match gender {\n        Gender::Other(text) =\u003e assert_eq!(text, \"none\"),\n        _ =\u003e panic!(\"Unexpected!\")\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoumanash%2Fbanjin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoumanash%2Fbanjin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoumanash%2Fbanjin/lists"}