@@ -18,10 +18,10 @@ extern crate syntax_pos;
18
18
extern crate rustc;
19
19
extern crate rustc_plugin;
20
20
21
- use syntax:: parse:: token:: { self , str_to_ident, NtExpr , NtPat } ;
21
+ use syntax:: parse:: token:: { str_to_ident, NtExpr , NtPat } ;
22
22
use syntax:: ast:: { Pat } ;
23
23
use syntax:: tokenstream:: { TokenTree } ;
24
- use syntax:: ext:: base:: { ExtCtxt , MacResult , DummyResult , MacEager } ;
24
+ use syntax:: ext:: base:: { ExtCtxt , MacResult , MacEager } ;
25
25
use syntax:: ext:: build:: AstBuilder ;
26
26
use syntax:: ext:: tt:: macro_parser:: { MatchedSeq , MatchedNonterminal } ;
27
27
use syntax:: ext:: tt:: macro_parser:: { Success , Failure , Error } ;
@@ -30,35 +30,12 @@ use syntax::ptr::P;
30
30
use syntax_pos:: Span ;
31
31
use rustc_plugin:: Registry ;
32
32
33
- fn expand_mbe_matches ( cx : & mut ExtCtxt , sp : Span , args : & [ TokenTree ] )
33
+ fn expand_mbe_matches ( cx : & mut ExtCtxt , _ : Span , args : & [ TokenTree ] )
34
34
-> Box < MacResult + ' static > {
35
35
36
36
let mbe_matcher = quote_matcher ! ( cx, $matched: expr, $( $pat: pat) |+) ;
37
-
38
- let mac_expr = match TokenTree :: parse ( cx, & mbe_matcher[ ..] , args) {
39
- Success ( map) => {
40
- match ( & * map[ & str_to_ident ( "matched" ) ] , & * map[ & str_to_ident ( "pat" ) ] ) {
41
- ( & MatchedNonterminal ( NtExpr ( ref matched_expr) ) ,
42
- & MatchedSeq ( ref pats, seq_sp) ) => {
43
- let pats: Vec < P < Pat > > = pats. iter ( ) . map ( |pat_nt|
44
- if let & MatchedNonterminal ( NtPat ( ref pat) ) = & * * pat_nt {
45
- pat. clone ( )
46
- } else {
47
- unreachable ! ( )
48
- }
49
- ) . collect ( ) ;
50
- let arm = cx. arm ( seq_sp, pats, cx. expr_bool ( seq_sp, true ) ) ;
51
-
52
- quote_expr ! ( cx,
53
- match $matched_expr {
54
- $arm
55
- _ => false
56
- }
57
- )
58
- }
59
- _ => unreachable ! ( )
60
- }
61
- }
37
+ let map = match TokenTree :: parse ( cx, & mbe_matcher, args) {
38
+ Success ( map) => map,
62
39
Failure ( _, tok) => {
63
40
panic ! ( "expected Success, but got Failure: {}" , parse_failure_msg( tok) ) ;
64
41
}
@@ -67,6 +44,34 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
67
44
}
68
45
} ;
69
46
47
+ let matched_nt = match * map[ & str_to_ident ( "matched" ) ] {
48
+ MatchedNonterminal ( ref nt) => nt. clone ( ) ,
49
+ _ => unreachable ! ( ) ,
50
+ } ;
51
+
52
+ let mac_expr = match ( & * matched_nt, & * map[ & str_to_ident ( "pat" ) ] ) {
53
+ ( & NtExpr ( ref matched_expr) , & MatchedSeq ( ref pats, seq_sp) ) => {
54
+ let pats: Vec < P < Pat > > = pats. iter ( ) . map ( |pat_nt| {
55
+ match * * pat_nt {
56
+ MatchedNonterminal ( ref nt) => match * * nt {
57
+ NtPat ( ref pat) => pat. clone ( ) ,
58
+ _ => unreachable ! ( ) ,
59
+ } ,
60
+ _ => unreachable ! ( ) ,
61
+ }
62
+ } ) . collect ( ) ;
63
+ let arm = cx. arm ( seq_sp, pats, cx. expr_bool ( seq_sp, true ) ) ;
64
+
65
+ quote_expr ! ( cx,
66
+ match $matched_expr {
67
+ $arm
68
+ _ => false
69
+ }
70
+ )
71
+ }
72
+ _ => unreachable ! ( )
73
+ } ;
74
+
70
75
MacEager :: expr ( mac_expr)
71
76
}
72
77
0 commit comments