perrymil
perrymil

Reputation: 43

What is the difference between Syntactic macros and Procedural macros?

What is the difference between procedural macros and syntactic macros? Rust refers to its macro system as procedural, but I've seen language articles refer to a system like the rust macro system as syntactic macros. Syntactic macros would appear to have access to all or part of the AST when parsing them. Which appears to be what Rust has.

Upvotes: 3

Views: 1689

Answers (1)

kmdreko
kmdreko

Reputation: 59817

Rust macros are syntactic; they work on the AST level.

What might be tripping you up in terminology is Rust has two flavors of macros that differ in how they are written and how they can be used. There are declarative macros (also called "macros by example") that are created by invocations of macro_rules!. And there are procedural macros, which are written as functions that handle TokenStreams as input and output (can be used as attributes, in derives, or like functions).

See also:

Upvotes: 5

Related Questions