@@ -13,7 +13,7 @@ use codemap::{Span, DUMMY_SP};
13
13
use ext:: base:: { ExtCtxt , MacResult , SyntaxExtension } ;
14
14
use ext:: base:: { NormalTT , TTMacroExpander } ;
15
15
use ext:: tt:: macro_parser:: { Success , Error , Failure } ;
16
- use ext:: tt:: macro_parser:: { NamedMatch , MatchedSeq , MatchedNonterminal } ;
16
+ use ext:: tt:: macro_parser:: { MatchedSeq , MatchedNonterminal } ;
17
17
use ext:: tt:: macro_parser:: parse;
18
18
use parse:: lexer:: new_tt_reader;
19
19
use parse:: parser:: Parser ;
@@ -129,15 +129,15 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
129
129
struct MacroRulesMacroExpander {
130
130
name : ast:: Ident ,
131
131
imported_from : Option < ast:: Ident > ,
132
- lhses : Vec < Rc < NamedMatch > > ,
133
- rhses : Vec < Rc < NamedMatch > > ,
132
+ lhses : Vec < TokenTree > ,
133
+ rhses : Vec < TokenTree > ,
134
134
}
135
135
136
136
impl TTMacroExpander for MacroRulesMacroExpander {
137
137
fn expand < ' cx > ( & self ,
138
138
cx : & ' cx mut ExtCtxt ,
139
139
sp : Span ,
140
- arg : & [ ast :: TokenTree ] )
140
+ arg : & [ TokenTree ] )
141
141
-> Box < MacResult +' cx > {
142
142
generic_extension ( cx,
143
143
sp,
@@ -154,9 +154,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
154
154
sp : Span ,
155
155
name : ast:: Ident ,
156
156
imported_from : Option < ast:: Ident > ,
157
- arg : & [ ast :: TokenTree ] ,
158
- lhses : & [ Rc < NamedMatch > ] ,
159
- rhses : & [ Rc < NamedMatch > ] )
157
+ arg : & [ TokenTree ] ,
158
+ lhses : & [ TokenTree ] ,
159
+ rhses : & [ TokenTree ] )
160
160
-> Box < MacResult +' cx > {
161
161
if cx. trace_macros ( ) {
162
162
println ! ( "{}! {{ {} }}" ,
@@ -169,25 +169,17 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
169
169
let mut best_fail_msg = "internal error: ran no matchers" . to_string ( ) ;
170
170
171
171
for ( i, lhs) in lhses. iter ( ) . enumerate ( ) { // try each arm's matchers
172
- match * * lhs {
173
- MatchedNonterminal ( NtTT ( ref lhs_tt) ) => {
174
- let lhs_tt = match * * lhs_tt {
172
+ let lhs_tt = match * lhs {
175
173
TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
176
174
_ => panic ! ( cx. span_fatal( sp, "malformed macro lhs" ) )
177
175
} ;
178
176
179
177
match TokenTree :: parse ( cx, lhs_tt, arg) {
180
178
Success ( named_matches) => {
181
- let rhs = match * rhses[ i] {
182
- // okay, what's your transcriber?
183
- MatchedNonterminal ( NtTT ( ref tt) ) => {
184
- match * * tt {
179
+ let rhs = match rhses[ i] {
185
180
// ignore delimiters
186
181
TokenTree :: Delimited ( _, ref delimed) => delimed. tts . clone ( ) ,
187
182
_ => panic ! ( cx. span_fatal( sp, "macro rhs must be delimited" ) ) ,
188
- }
189
- } ,
190
- _ => cx. span_bug ( sp, "bad thing in rhs" )
191
183
} ;
192
184
// rhs has holes ( `$id` and `$(...)` that need filled)
193
185
let trncbr = new_tt_reader ( & cx. parse_sess ( ) . span_diagnostic ,
@@ -216,9 +208,6 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
216
208
panic ! ( cx. span_fatal( err_sp. substitute_dummy( sp) , & msg[ ..] ) )
217
209
}
218
210
}
219
- }
220
- _ => cx. bug ( "non-matcher found in parsed lhses" )
221
- }
222
211
}
223
212
224
213
panic ! ( cx. span_fatal( best_fail_spot. substitute_dummy( sp) , & best_fail_msg[ ..] ) ) ;
@@ -284,7 +273,12 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
284
273
285
274
// Extract the arguments:
286
275
let lhses = match * * argument_map. get ( & lhs_nm. name ) . unwrap ( ) {
287
- MatchedSeq ( ref s, _) => /* FIXME (#2543) */ ( * s) . clone ( ) ,
276
+ MatchedSeq ( ref s, _) => {
277
+ s. iter ( ) . map ( |m| match * * m {
278
+ MatchedNonterminal ( NtTT ( ref tt) ) => ( * * tt) . clone ( ) ,
279
+ _ => cx. span_bug ( def. span , "wrong-structured lhs" )
280
+ } ) . collect ( )
281
+ }
288
282
_ => cx. span_bug ( def. span , "wrong-structured lhs" )
289
283
} ;
290
284
@@ -293,7 +287,12 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
293
287
}
294
288
295
289
let rhses = match * * argument_map. get ( & rhs_nm. name ) . unwrap ( ) {
296
- MatchedSeq ( ref s, _) => /* FIXME (#2543) */ ( * s) . clone ( ) ,
290
+ MatchedSeq ( ref s, _) => {
291
+ s. iter ( ) . map ( |m| match * * m {
292
+ MatchedNonterminal ( NtTT ( ref tt) ) => ( * * tt) . clone ( ) ,
293
+ _ => cx. span_bug ( def. span , "wrong-structured rhs" )
294
+ } ) . collect ( )
295
+ }
297
296
_ => cx. span_bug ( def. span , "wrong-structured rhs" )
298
297
} ;
299
298
@@ -307,11 +306,10 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
307
306
NormalTT ( exp, Some ( def. span ) , def. allow_internal_unstable )
308
307
}
309
308
310
- fn check_lhs_nt_follows ( cx : & mut ExtCtxt , lhs : & NamedMatch , sp : Span ) {
311
- // lhs is going to be like MatchedNonterminal(NtTT( TokenTree::Delimited(...)) ), where the
309
+ fn check_lhs_nt_follows ( cx : & mut ExtCtxt , lhs : & TokenTree , sp : Span ) {
310
+ // lhs is going to be like TokenTree::Delimited(...), where the
312
311
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
313
312
match lhs {
314
- & MatchedNonterminal ( NtTT ( ref inner) ) => match & * * inner {
315
313
& TokenTree :: Delimited ( _, ref tts) => {
316
314
check_matcher ( cx, tts. tts . iter ( ) , & Eof ) ;
317
315
} ,
@@ -320,9 +318,6 @@ fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &NamedMatch, sp: Span) {
320
318
} ,
321
319
_ => cx. span_err ( sp, "Invalid macro matcher; matchers must be contained \
322
320
in balanced delimiters or a repetition indicator")
323
- } ,
324
- _ => cx. span_bug ( sp, "wrong-structured lhs for follow check (didn't find a \
325
- MatchedNonterminal)")
326
321
} ;
327
322
// we don't abort on errors on rejection, the driver will do that for us
328
323
// after parsing/expansion. we can report every error in every macro this way.
0 commit comments