@@ -26,15 +26,21 @@ macro_rules! printer {
26
26
}
27
27
```
28
28
29
- ` $mvar ` is called a _ metavariable_ . Unlike normal variables, rather than binding
30
- to a value in a computation, a metavariable binds _ at compile time_ to a tree of
31
- _ tokens_ . A _ token_ zero or more symbols that together have some meaning. For
32
- example, in our example definition, ` print ` , ` $mvar ` , ` => ` , ` { ` are all tokens
33
- (though that's not an exhaustive list). There are also other special tokens,
34
- such as ` EOF ` , which indicates that there are no more tokens. The process of
35
- producing a stream of tokens from the raw bytes of the source file is called
36
- _ lexing_ . For more information about _ lexing_ , see the [ Parsing
37
- chapter] [ parsing ] of this book.
29
+ ` $mvar ` is called a _ metavariable_ . Unlike normal variables, rather than
30
+ binding to a value in a computation, a metavariable binds _ at compile time_ to
31
+ a tree of _ tokens_ . A _ token_ is a single "unit" of the grammar, such as an
32
+ identifier (e.g., ` foo ` ) or punctuation (e.g., ` => ` ). There are also other
33
+ special tokens, such as ` EOF ` , which indicates that there are no more tokens.
34
+ Token trees resulting from paired parentheses-like characters (` ( ` ...` ) ` ,
35
+ ` [ ` ...` ] ` , and ` { ` ...` } ` ) -- they include the open and close and all the tokens
36
+ in between (we do require that parentheses-like characters be balanced). Having
37
+ macro expansion operate on token streams rather than the raw bytes of a source
38
+ file abstracts away a lot of complexity. The macro expander (and much of the
39
+ rest of the compiler) doesn't really care that much about the exact line and
40
+ column of some syntactic construct in the code; it cares about what constructs
41
+ are used in the code. Using tokens allows us to care about _ what_ without
42
+ worrying about _ where_ . For more information about tokens, see the
43
+ [ Parsing] [ parsing ] chapter of this book.
38
44
39
45
Whenever we refer to the "example _ invocation_ ", we mean the following snippet:
40
46
@@ -44,7 +50,7 @@ printer!(print foo); // Assume `foo` is a variable defined somewhere else...
44
50
45
51
The process of expanding the macro invocation into the syntax tree
46
52
` println!("{}", foo) ` and then expanding that into a call to ` Display::fmt ` is
47
- called _ macro expansion_ , it is the topic of this chapter.
53
+ called _ macro expansion_ , and it is the topic of this chapter.
48
54
49
55
### The macro parser
50
56
0 commit comments