You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This attempts to clarify some details about proc-macro tokens, in
particular the differences in handling `_` from `macro_rules`. This
includes several changes:
- Removed the wordy description of a `macro_rules` TokenTree. This
is already defined in the grammar in more detail. This does remove
the sentence discussing metavariable substitutions. I would prefer
to defer this to a more detailed description in the `macro_rules`
chapter on how metavariable substitutions work.
- Removed the English description of a proc-macro token tree, and
instead write it as a grammar production.
Closes#2020Closes#1236
Copy file name to clipboardExpand all lines: src/procedural-macros.md
+64-32Lines changed: 64 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -318,45 +318,75 @@ r[macro.proc.token]
318
318
## Declarative macro tokens and procedural macro tokens
319
319
320
320
r[macro.proc.token.intro]
321
-
Declarative `macro_rules` macros and procedural macros use similar, but
322
-
different definitions for tokens (or rather [`TokenTree`s].)
323
-
324
-
r[macro.proc.token.macro_rules]
325
-
Token trees in `macro_rules` (corresponding to `tt` matchers) are defined as
326
-
- Delimited groups (`(...)`, `{...}`, etc)
327
-
- All operators supported by the language, both single-character and
328
-
multi-character ones (`+`, `+=`).
329
-
- Note that this set doesn't include the single quote `'`.
330
-
- Literals (`"string"`, `1`, etc)
331
-
- Note that negation (e.g. `-1`) is never a part of such literal tokens,
332
-
but a separate operator token.
333
-
- Identifiers, including keywords (`ident`, `r#ident`, `fn`)
334
-
- Lifetimes (`'ident`)
335
-
- Metavariable substitutions in `macro_rules` (e.g. `$my_expr` in
336
-
`macro_rules! mac { ($my_expr: expr) => { $my_expr } }` after the `mac`'s
337
-
expansion, which will be considered a single token tree regardless of the
338
-
passed expression)
321
+
Declarative `macro_rules` macros and procedural macros use similar but different definitions for tokens. Token trees in `macro_rules` (corresponding to `tt` matchers) are defined as the [TokenTree] production. Token trees for procedural macros are described below.
339
322
340
323
r[macro.proc.token.tree]
341
-
Token trees in procedural macros are defined as
342
-
- Delimited groups (`(...)`, `{...}`, etc)
343
-
- All punctuation characters used in operators supported by the language (`+`,
344
-
but not `+=`), and also the single quote `'` character (typically used in
345
-
lifetimes, see below for lifetime splitting and joining behavior)
346
-
- Literals (`"string"`, `1`, etc)
347
-
- Negation (e.g. `-1`) is supported as a part of integer
348
-
and floating point literals.
349
-
- Identifiers, including keywords (`ident`, `r#ident`, `fn`)
0 commit comments