Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is macro_rules a regular macro?

I'm trying to understand rust macro syntax. Here I read that macro may be invoked generally in 3 flavours:

mymacro!(<tokens>);
mymacro![<tokens>];
mymacro!{<tokens>};

...and then I see an example macro definition also using macro (macro_rules), but the syntax doesn't conform to these rules:

macro_rules! name {<tokens>}

Is name a token and we have 4-th legal macro invocation form here or macro_rules is rather a keyword than just macro and uses special syntax not available for regular macros?

like image 593
ardabro Avatar asked Mar 01 '23 10:03

ardabro


1 Answers

No, macro_rules is a special "directive". You can check the compiler syntax tree here. The important part is:

Syntax
MacroRulesDefinition :
   macro_rules ! IDENTIFIER MacroRulesDef

You can see that it is the entry point of the macros syntax.

like image 181
Netwave Avatar answered Mar 06 '23 18:03

Netwave