| Crates.io | matcher-proc-macro |
| lib.rs | matcher-proc-macro |
| version | 0.1.0 |
| created_at | 2025-05-12 12:33:56.294939+00 |
| updated_at | 2025-05-12 12:33:56.294939+00 |
| description | A proc macro to generate an SExpr pattern matcher - for everything(-lang) and macro-lang |
| homepage | |
| repository | https://github.com/mendelsshop/everything/tree/main/matcher |
| max_upload_size | |
| id | 1670523 |
| size | 20,452 |
A proc macro to generate an SExpr pattern matcher - for everything(-lang) and macro-lang
Provides two macros: match_syntax and match_syntax_as, which are pretty much the same, except the type the match_syntax generates is basically opaque.
Will only work in everything(-lang) or macro-lang as it relies on some data structures and functions that they both share, at a later point I might split out those data structures into another crate, in which case this would usuable without those crates.
sexpr => <symbol>
| <symbol>":id"
| "id"
| "("<sexpr>+ "." <sexpr>")"
| "("<sexpr>*")"
| <sexpr> "..."
| <sexpr> "..+"
symbol => ([a-zA-Z]|_)([a-zA-Z0-9]|_)*
match_syntax!(sexpr)match_syntax_as(StructName as sexpr)Example: let matcher = match_syntax((foo bar));.
The result of match_syntax or match_syntax_as is the matches method of opaque struct or a the creation of a new struct with a matches method on it (in the case of match_syntax_as).
In the case of match_syntax: do match_syntax(sexpr)(sexpr_to_run_matcher_on).
In the case of match_syntax_as: use the matches method on the newline generated struct like StructName::matches(sexpr_to_run_matcher_on).
Note: sexpr_to_run_matcher_on has different syntax then sexpr. See note at the beggining.
Example: let results = matcher(sexpr!((a (b c))))?, sexpr! is a macro from everything(-lang) or macro-lang.
Assuming you ran the matcher and unrwapped the result, you just do access the field like you declared in the original sexpr.
Example: results.foo.
Note: if you used an :id postfix for your symbol pattern then to access from the struct it will be <symbol>_id.