macro
SkillDev toolsGuides your agent to write procedural macros for Topcoat correctly.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the macro skill
About this capability
Always use this skill before writing procedural macros for Topcoat
What this skill tells your AI
The instructions your AI receives, as published by tokio-rs/topcoat in .agents/skills/macro/SKILL.md and read by ahel’s review.
AST nodes
- Like
synnodes, an AST node is a lossless record of the syntax it matched: every field ispuband holds the tokens as written, spans included. The original source should be reconstructible from the node. Field order does not have to match the source, but spans must be preserved. - Parsing validates, it does not interpret. A
Parseimpl rejects what is not valid syntax and stores everything else verbatim in token fields; it never normalizes, resolves, or drops information on the way in. - Semantics are derived from the AST, not baked into it. Put the interpretation in methods on the node that read its own fields, so the node stays a faithful representation of the source and the meaning stays separate from it.
Parsing
- In
Parseimpls, parse directly into theSelf { ... }fields (Self { x: input.parse()? }) rather than throughletbindings. Use aletonly when a parsed value must be inspected to decide how to parse a later field. - To parse custom keywords that are not re-emitted into the generated code, create a private
mod kwwithsyn::custom_keyword!invocations instead of parsingsyn::Ident. Useinput.lookahead1()if it makes sense. - Instead of manually peeking for optional AST nodes in the input stream at the call site, implement
ParseOptionand parse them withinput.call(Node::parse_option)?.
Entry points
The macro/ crate only bridges proc_macro::TokenStream to the grammar crate that holds the AST and the codegen. Every entry point is a parse, a match, and a to_compile_error() on the error arm; no logic lives in lib.rs.
An attribute macro receives two token streams, so it gets three types: one Parse node per stream and a tuple struct pairing them, which is the node the codegen hangs off.
// grammar crate
pub struct ProcedureAttr {}
pub struct ProcedureItem { ... }
pub struct Procedure(ProcedureAttr, ProcedureItem);
impl Procedure {
#[must_use]
pub fn new(attr: ProcedureAttr, item: ProcedureItem) -> Self {
Self(attr, item)
}
pub fn parse(attr: TokenStream, item: TokenStream) -> syn::Result<Self> {
Ok(Self::new(syn::parse2(attr)?, syn::parse2(item)?))
}
}
impl ToTokens for Procedure { ... }
Parse stays per stream, since neither stream alone is the macro input. The pairing type owns the inherent parse that joins them and the ToTokens impl that expands them, which keeps the entry point a one-liner:
// macro crate
#[doc = include_str!("../docs/procedure.md")]
#[proc_macro_attribute]
pub fn procedure(attr: TokenStream, item: TokenStream) -> TokenStream {
match topcoat_runtime_grammar::procedure::Procedure::parse(attr.into(), item.into()) {
Ok(value) => quote! { #value }.into(),
Err(error) => error.to_compile_error().into(),
}
}
A function-like macro has a single input, so it needs no pairing type: syn::parse_macro_input! straight into its AST node, then expand.
Signals
- GitHub stars
- 5k
- Forks
- 176
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
macro- Source
- github.com/tokio-rs/topcoat