10
10
11
11
use std:: map:: HashMap ;
12
12
13
- use ast:: { crate , expr_, expr_mac, mac_invoc , mac_invoc_tt,
13
+ use ast:: { crate , expr_, expr_mac, mac_invoc_tt,
14
14
tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi} ;
15
15
use fold:: * ;
16
16
use ext:: base:: * ;
@@ -31,51 +31,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
31
31
expr_mac( ref mac) => {
32
32
33
33
match ( * mac) . node {
34
- // Old-style macros. For compatibility, will erase this whole
35
- // block once we've transitioned.
36
- mac_invoc( pth, args, body) => {
37
- assert ( vec:: len ( pth. idents ) > 0 u) ;
38
- /* using idents and token::special_idents would make the
39
- the macro names be hygienic */
40
- let extname = cx. parse_sess ( ) . interner . get ( pth. idents [ 0 ] ) ;
41
- match exts. find ( * extname) {
42
- None => {
43
- cx. span_fatal ( pth. span ,
44
- fmt ! ( "macro undefined: '%s'" , * extname) )
45
- }
46
- Some ( item_decorator( _) ) => {
47
- cx. span_fatal (
48
- pth. span ,
49
- fmt ! ( "%s can only be used as a decorator" , * extname) ) ;
50
- }
51
- Some ( normal ( { expander : exp, span : exp_sp} ) ) => {
52
-
53
- cx. bt_push ( ExpandedFrom ( { call_site: s,
54
- callie : { name : * extname, span : exp_sp} } ) ) ;
55
- let expanded = exp ( cx, ( * mac) . span , args, body) ;
56
-
57
- //keep going, outside-in
58
- let fully_expanded = fld. fold_expr ( expanded) . node ;
59
- cx. bt_pop ( ) ;
60
-
61
- ( fully_expanded, s)
62
- }
63
- Some ( macro_defining( ext) ) => {
64
- let named_extension = ext ( cx, ( * mac) . span , args, body) ;
65
- exts. insert ( named_extension. name , named_extension. ext ) ;
66
- ( ast:: expr_rec ( ~[ ] , None ) , s)
67
- }
68
- Some ( normal_tt( _) ) => {
69
- cx. span_fatal ( pth. span ,
70
- fmt ! ( "this tt-style macro should be \
71
- invoked '%s!(...)'", * extname) )
72
- }
73
- Some ( item_tt( * ) ) => {
74
- cx. span_fatal ( pth. span ,
75
- ~"cannot use item macros in this context") ;
76
- }
77
- }
78
- }
79
34
80
35
// Token-tree macros, these will be the only case when we're
81
36
// finished transitioning.
@@ -130,7 +85,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
130
85
131
86
}
132
87
}
133
- _ => cx. span_bug ( ( * mac) . span , ~"naked syntactic bit")
134
88
}
135
89
}
136
90
_ => orig ( e, s, fld)
@@ -165,8 +119,8 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
165
119
ast:: meta_list( ref n, _) => ( * n)
166
120
} ;
167
121
match exts. find ( mname) {
168
- None | Some ( normal( _) ) | Some ( macro_defining ( _ ) )
169
- | Some ( normal_tt( _) ) | Some ( item_tt( * ) ) => items,
122
+ None | Some ( normal( _) )
123
+ | Some ( normal_tt( _) ) | Some ( item_tt( * ) ) => items,
170
124
Some ( item_decorator( dec_fn) ) => {
171
125
cx. bt_push ( ExpandedFrom ( { call_site: attr. span ,
172
126
callie : { name : copy mname,
@@ -209,36 +163,16 @@ fn expand_item(exts: HashMap<~str, syntax_extension>,
209
163
}
210
164
}
211
165
212
- // avoid excess indentation when a series of nested `match`es
213
- // has only one "good" outcome
214
- macro_rules! biased_match (
215
- ( ( $e : expr) ~ ( $p : pat) else $err : stmt ;
216
- $( ( $e_cdr: expr) ~ ( $p_cdr: pat) else $err_cdr: stmt ; ) *
217
- => $body: expr
218
- ) => (
219
- match $e {
220
- $p => {
221
- biased_match!( $( ( $e_cdr) ~ ( $p_cdr) else $err_cdr ; ) *
222
- => $body)
223
- }
224
- _ => { $err }
225
- }
226
- ) ;
227
- ( => $body: expr ) => ( $body )
228
- )
229
-
230
-
231
166
// Support for item-position macro invocations, exactly the same
232
167
// logic as for expression-position macro invocations.
233
168
fn expand_item_mac ( exts : HashMap < ~str , syntax_extension > ,
234
169
cx : ext_ctxt , & & it: @ast:: item ,
235
170
fld : ast_fold ) -> Option < @ast:: item > {
236
- let ( pth, tts) = biased_match!(
237
- ( it. node) ~ ( item_mac( { node: mac_invoc_tt( pth, ref tts) , _} ) ) else {
238
- cx. span_bug( it. span, ~"invalid item macro invocation")
239
- };
240
- => (pth, (*tts))
241
- );
171
+
172
+ let ( pth, tts) = match it. node {
173
+ item_mac ( { node : mac_invoc_tt( pth, ref tts) , _} ) => ( pth, ( * tts) ) ,
174
+ _ => cx. span_bug ( it. span , ~"invalid item macro invocation")
175
+ } ;
242
176
243
177
let extname = cx. parse_sess ( ) . interner . get ( pth. idents [ 0 ] ) ;
244
178
let expanded = match exts. find ( * extname) {
@@ -293,12 +227,15 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
293
227
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
294
228
-> (stmt_, span)
295
229
{
296
- let (mac, pth, tts, semi) = biased_match! (
297
- (s) ~ (stmt_mac(ref mac, semi)) else return orig(s, sp, fld);
298
- ((*mac).node) ~ (mac_invoc_tt(pth, ref tts)) else {
299
- cx.span_bug((*mac).span, ~" naked syntactic bit")
300
- };
301
- => ((*mac), pth, (*tts), semi));
230
+
231
+ let (mac, pth, tts, semi) = match s {
232
+ stmt_mac(ref mac, semi) => {
233
+ match (*mac).node {
234
+ mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi)
235
+ }
236
+ }
237
+ _ => return orig(s, sp, fld)
238
+ };
302
239
303
240
assert(vec::len(pth.idents) == 1u);
304
241
let extname = cx.parse_sess().interner.get(pth.idents[0]);
0 commit comments