{"id":14991958,"url":"https://github.com/nrc/proc-macro-rules","last_synced_at":"2025-04-07T15:05:45.524Z","repository":{"id":62442950,"uuid":"163779341","full_name":"nrc/proc-macro-rules","owner":"nrc","description":"Macro-rules-style syntax matching for procedural macros","archived":false,"fork":false,"pushed_at":"2023-11-07T03:12:12.000Z","size":45,"stargazers_count":52,"open_issues_count":14,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T14:09:09.913Z","etag":null,"topics":["macros","parsing","pattern-matching","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nrc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-02T01:16:20.000Z","updated_at":"2025-02-20T18:25:16.000Z","dependencies_parsed_at":"2023-11-07T05:41:13.143Z","dependency_job_id":null,"html_url":"https://github.com/nrc/proc-macro-rules","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrc%2Fproc-macro-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrc%2Fproc-macro-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrc%2Fproc-macro-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrc%2Fproc-macro-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrc","download_url":"https://codeload.github.com/nrc/proc-macro-rules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675596,"owners_count":20977376,"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":["macros","parsing","pattern-matching","rust"],"created_at":"2024-09-24T15:00:37.059Z","updated_at":"2025-04-07T15:05:45.493Z","avatar_url":"https://github.com/nrc.png","language":"Rust","readme":"# proc-macro-rules\n\n`macro_rules`-style syntax matching for procedural macros.\n\nThis crate is work-in-progress, incomplete, and probably buggy!\n\nExample:\n\n```rust\nrules!(tokens =\u003e {\n    ($finish:ident ($($found:ident)*) # [ $($inner:tt)* ] $($rest:tt)*) =\u003e {\n        for f in found {\n            do_something(finish, f, inner, rest[0]);\n        }\n    }\n    (foo $($bar:expr)?) =\u003e {\n        match bar {\n            Some(e) =\u003e foo_with_expr(e),\n            None =\u003e foo_no_expr(),\n        }\n    }\n});\n```\n\n## Using proc-macro-rules\n\nAdd `proc-macro-rules = \"0.3.0\"` (or `proc-macro-rules = \"0.2.1\"` for versions between 1.31 and 1.56) to your Cargo.toml.\n\nImport the `rules` macro with `use proc_macro_rules::rules`, then use with `rules!(tokens =\u003e { branches });` where `tokens` is an expression which evaluates to a `TokenStream` (such as the argument in the definition of a procedural macro).\n\nEach branch in `branches` should have the form `( pattern ) =\u003e { body }` where `pattern` is a macro-rules-style pattern (using all the same syntax for meta-variables, AST nodes, repetition, etc.) and `body` is rust code executed when the pattern is matched. Within `body`, any meta-variables in the pattern are bound to variables of an appropriate type from either the [proc_macro2](https://github.com/alexcrichton/proc-macro2) or [syn](https://github.com/dtolnay/syn) crates. Where a meta-variable is inside a repetition or option clause, it will be wrapped in a `Vec` or `Option`, respectively.\n\nFor example, in the first branch in the above example `ident` has type `syn::Ident` and `inner` has type `Vec\u003cproc_macro2::TokenTree\u003e`.\n\n\n## Building and testing\n\nUse `cargo build` to build, `cargo test --all` to test.\n\n\n## Contributing\n\nContributions are very welcome! It would be great to know things which are missing or incorrect (in general we should have the same behaviour as `macro_rules`, so anything different is incorrect). Issues, code, docs, tests, and corrections are all welcome.\n","funding_links":[],"categories":["Summary"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrc%2Fproc-macro-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrc%2Fproc-macro-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrc%2Fproc-macro-rules/lists"}