6

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?

ardabro
  • 1,907
  • 16
  • 31

1 Answers1

9

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.

Netwave
  • 40,134
  • 6
  • 50
  • 93