As far as i know we can use macro as DSL
And rustfmt stop format things in {}
and macro_rules is just like match with special syntax
So can we let rustfmt learn how to format DSL from MacroMatcher
PS. I think tt
will not fmt
As far as i know we can use macro as DSL
And rustfmt stop format things in {}
and macro_rules is just like match with special syntax
So can we let rustfmt learn how to format DSL from MacroMatcher
PS. I think tt
will not fmt
I don't think rustfmt has a hook or pre-/post-processing mechanism that allows you to add rules to format your macro invocations. AFAIK, this is still the state of macro formatting in rustfmt:
I'm not sure what rustfmt does with macros, but RustRover does already check the syntax of declarative macros while the user types them, though I think it does it as it does the rest: by compiling the code in background. So if it's able to check the syntax in background, it must be possible to parse the macro explicitly (instead of leaving it to the compiler). And indeed, the syntax isn't very hard to parse.
The question is: how should it format custom macros instances? You'd need to define that format somehow.
I have an idea:
most macro use tt to recursion match token.
If it's simple,tt will match another rule in macro, Then using recursion format, Each recursive call is treated as a child node. Then format use node tree, add indent between sub node
Maybe that's should a extension of cargo fmt. I will try to write a sample later
well it's harder than i think. maybe need to write a macro syntax interpreter
Is it possible to let me LEARN macro_rules syntax?