Vacro Parser
The Declarative Parsing Kernel for Vacro
Introduction
Vacro Parser is the core declarative parsing engine of the Vacro framework. It provides a macro_rules!-like DSL to simplify the writing of syn-based parsers for Rust Procedural Macros.
It allows you to define AST structures and parsing logic declaratively, eliminating the boilerplate of imperative input.parse()? calls.
Installation
Add this to your Cargo.toml:
[]
= "0.1.8"
Core Features
1. define!: Define Parsing Structs
Use define! to define a struct that automatically implements syn::parse::Parse.
use ;
// Define a struct named MyFn, it automatically implements the Parse trait
define!;
// Usage in a proc-macro
2. bind!: On-the-fly Parsing
Use bind! to consume a portion of a TokenStream within existing imperative logic.
use ;
use bind;
Syntax Reference
| Syntax | Description | Example |
|---|---|---|
literal |
Matches exact tokens | fn, ->, struct |
#(x: T) |
Named Capture: Captures type T into field x |
#(name: Ident) |
#(x?: T) |
Optional Capture: Option<T> |
#(ret?: Type) |
#(x*[sep]: T) |
Iterative Capture: Punctuated<T, sep> |
#(args*[,]: FnArg) |
#(T) |
Anonymous Match: Validates T exists but doesn't capture |
#(Ident) |
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
More user-friendly prompts (v0.1.6)
You can use the help! macro of vacro-report to provide more helpful suggestions for the content. If you are using vacro, you only need to enable the report feature.
= { = "0.1.8" }
= { = "0.1.3", = ["parser"] }
# vacro = { version = "0.2.3", features = ["parser", "report"] }
use define;
use help;
use ;
help!;
define!;