{"id":13626675,"url":"https://github.com/Hejsil/mecha","last_synced_at":"2025-04-16T15:31:26.329Z","repository":{"id":39610577,"uuid":"271253861","full_name":"Hejsil/mecha","owner":"Hejsil","description":"A parser combinator library for Zig","archived":false,"fork":false,"pushed_at":"2024-09-26T06:54:10.000Z","size":111,"stargazers_count":468,"open_issues_count":6,"forks_count":21,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T17:31:23.993Z","etag":null,"topics":["functional","parser","parser-combinators","parser-library","parsers","zig","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hejsil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":["Hejsil"]}},"created_at":"2020-06-10T11:02:59.000Z","updated_at":"2024-10-27T20:23:31.000Z","dependencies_parsed_at":"2024-01-02T08:02:28.091Z","dependency_job_id":"bfa69330-7d9c-4533-afea-605060535b2e","html_url":"https://github.com/Hejsil/mecha","commit_stats":{"total_commits":147,"total_committers":17,"mean_commits":8.647058823529411,"dds":0.4625850340136054,"last_synced_commit":"aa74b85409b52925ca1722cd9d05004a53f3a44c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fmecha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fmecha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fmecha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fmecha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hejsil","download_url":"https://codeload.github.com/Hejsil/mecha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223716676,"owners_count":17191090,"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":["functional","parser","parser-combinators","parser-library","parsers","zig","zig-library","zig-package"],"created_at":"2024-08-01T21:02:26.200Z","updated_at":"2025-04-16T15:31:26.322Z","avatar_url":"https://github.com/Hejsil.png","language":"Zig","readme":"# Mecha\n\nA parser combinator library for the [`Zig`](https://ziglang.org/)\nprogramming language. Time to make your own parser mech!\n\n```zig\nconst mecha = @import(\"mecha\");\nconst std = @import(\"std\");\n\nconst Rgb = struct {\n    r: u8,\n    g: u8,\n    b: u8,\n};\n\nfn toByte(v: u4) u8 {\n    return @as(u8, v) * 0x10 + v;\n}\n\nconst hex1 = mecha.int(u4, .{\n    .parse_sign = false,\n    .base = 16,\n    .max_digits = 1,\n}).map(toByte);\nconst hex2 = mecha.int(u8, .{\n    .parse_sign = false,\n    .base = 16,\n    .max_digits = 2,\n});\nconst rgb1 = mecha.manyN(hex1, 3, .{}).map(mecha.toStruct(Rgb));\nconst rgb2 = mecha.manyN(hex2, 3, .{}).map(mecha.toStruct(Rgb));\nconst rgb = mecha.combine(.{\n    mecha.ascii.char('#').discard(),\n    mecha.oneOf(.{ rgb2, rgb1 }),\n});\n\ntest \"rgb\" {\n    const testing = std.testing;\n    const allocator = testing.allocator;\n    const a = (try rgb.parse(allocator, \"#aabbcc\")).value.ok;\n    try testing.expectEqual(@as(u8, 0xaa), a.r);\n    try testing.expectEqual(@as(u8, 0xbb), a.g);\n    try testing.expectEqual(@as(u8, 0xcc), a.b);\n\n    const b = (try rgb.parse(allocator, \"#abc\")).value.ok;\n    try testing.expectEqual(@as(u8, 0xaa), b.r);\n    try testing.expectEqual(@as(u8, 0xbb), b.g);\n    try testing.expectEqual(@as(u8, 0xcc), b.b);\n\n    const c = (try rgb.parse(allocator, \"#000000\")).value.ok;\n    try testing.expectEqual(@as(u8, 0), c.r);\n    try testing.expectEqual(@as(u8, 0), c.g);\n    try testing.expectEqual(@as(u8, 0), c.b);\n\n    const d = (try rgb.parse(allocator, \"#000\")).value.ok;\n    try testing.expectEqual(@as(u8, 0), d.r);\n    try testing.expectEqual(@as(u8, 0), d.g);\n    try testing.expectEqual(@as(u8, 0), d.b);\n}\n```\n\n\n## Installation\n\nDevelopers tend to either use\n* The latest tagged release of Zig\n* The latest build of Zigs master branch\n\nDepending on which developer you are, you need to run different `zig fetch` commands:\n\n```sh\n# Version of mecha that works with a tagged release of Zig\n# Replace `\u003cREPLACE ME\u003e` with the version of mecha that you want to use\n# See: https://github.com/Hejsil/mecha/releases\nzig fetch --save https://github.com/Hejsil/mecha/archive/refs/tags/\u003cREPLACE ME\u003e.tar.gz\n\n# Version of mecha that works with latest build of Zigs master branch\nzig fetch --save git+https://github.com/Hejsil/mecha\n```\n\nThen add the following to `build.zig`:\n\n```zig\nconst mecha = b.dependency(\"mecha\", .{});\nexe.root_module.addImport(\"mecha\", clap.module(\"mecha\"));\n```\n\n","funding_links":["https://github.com/sponsors/Hejsil"],"categories":["Zig","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHejsil%2Fmecha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHejsil%2Fmecha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHejsil%2Fmecha/lists"}