@@ -227,7 +227,7 @@ only within the macro (i.e. it should not be visible outside the macro).
227
227
[code_dir]: https://github.com/rust-lang/rust/tree/master/compiler/rustc_expand/src/mbe
228
228
[code_mp]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/macro_parser
229
229
[code_mr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/macro_rules
230
- [code_parse_int]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/macro_parser/fn.parse_tt .html
230
+ [code_parse_int]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/macro_parser/struct.TtParser .html#method.parse_tt
231
231
[parsing]: ./the-parser.html
232
232
233
233
The context is attached to AST nodes. All AST nodes generated by macros have
@@ -503,9 +503,10 @@ The interface of the macro parser is as follows (this is slightly simplified):
503
503
504
504
``` rust,ignore
505
505
fn parse_tt(
506
- parser: &mut Cow<Parser>,
507
- ms: &[TokenTree],
508
- ) -> NamedParseResult
506
+ &mut self,
507
+ parser: &mut Cow<'_, Parser<'_>>,
508
+ matcher: &[MatcherLoc]
509
+ ) -> ParseResult
509
510
```
510
511
511
512
We use these items in macro parser:
@@ -515,20 +516,20 @@ We use these items in macro parser:
515
516
ask the MBE parser to parse. We will consume the raw stream of tokens and
516
517
output a binding of metavariables to corresponding token trees. The parsing
517
518
session can be used to report parser errors.
518
- - ` ms ` a _ matcher _ . This is a sequence of token trees that we want to match
519
- the token stream against.
519
+ - ` matcher ` is a sequence of ` MatcherLoc ` s that we want to match
520
+ the token stream against. They're converted from token trees before matching.
520
521
521
522
In the analogy of a regex parser, the token stream is the input and we are matching it
522
- against the pattern ` ms ` . Using our examples, the token stream could be the stream of
523
- tokens containing the inside of the example invocation ` print foo ` , while ` ms `
523
+ against the pattern ` matcher ` . Using our examples, the token stream could be the stream of
524
+ tokens containing the inside of the example invocation ` print foo ` , while ` matcher `
524
525
might be the sequence of token (trees) ` print $mvar:ident ` .
525
526
526
- The output of the parser is a ` NamedParseResult ` , which indicates which of
527
+ The output of the parser is a [ ` ParseResult ` ] , which indicates which of
527
528
three cases has occurred:
528
529
529
- - Success: the token stream matches the given matcher ` ms ` , and we have produced a binding
530
+ - Success: the token stream matches the given ` matcher ` , and we have produced a binding
530
531
from metavariables to the corresponding token trees.
531
- - Failure: the token stream does not match ` ms ` . This results in an error message such as
532
+ - Failure: the token stream does not match ` matcher ` . This results in an error message such as
532
533
"No rule expected token _ blah_ ".
533
534
- Error: some fatal error has occurred _ in the parser_ . For example, this
534
535
happens if there are more than one pattern match, since that indicates
@@ -607,6 +608,7 @@ Because the Rust ABI is unstable, we use the C ABI for this conversion.
607
608
[ stablets ] : https://doc.rust-lang.org/proc_macro/struct.TokenStream.html
608
609
[ pm ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/proc_macro/index.html
609
610
[ pms ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/proc_macro_server/index.html
611
+ [ `ParseResult` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/macro_parser/enum.ParseResult.html
610
612
611
613
TODO: more here. [ #1160 ] ( https://github.com/rust-lang/rustc-dev-guide/issues/1160 )
612
614
0 commit comments