@@ -50,11 +50,23 @@ pub struct SequenceRepetition {
50
50
/// The optional separator
51
51
pub separator : Option < Token > ,
52
52
/// Whether the sequence can be repeated zero (*), or one or more times (+)
53
- pub op : KleeneOp ,
53
+ pub kleene : KleeneToken ,
54
54
/// The number of `Match`s that appear in the sequence (and subsequences)
55
55
pub num_captures : usize ,
56
56
}
57
57
58
+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Debug , Copy ) ]
59
+ pub struct KleeneToken {
60
+ pub span : Span ,
61
+ pub op : KleeneOp ,
62
+ }
63
+
64
+ impl KleeneToken {
65
+ pub fn new ( op : KleeneOp , span : Span ) -> KleeneToken {
66
+ KleeneToken { span, op }
67
+ }
68
+ }
69
+
58
70
/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
59
71
/// for token sequences.
60
72
#[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Hash , Debug , Copy ) ]
@@ -273,15 +285,15 @@ fn parse_tree(
273
285
macro_node_id,
274
286
) ;
275
287
// Get the Kleene operator and optional separator
276
- let ( separator, op ) = parse_sep_and_kleene_op ( trees, span. entire ( ) , sess) ;
288
+ let ( separator, kleene ) = parse_sep_and_kleene_op ( trees, span. entire ( ) , sess) ;
277
289
// Count the number of captured "names" (i.e., named metavars)
278
290
let name_captures = macro_parser:: count_names ( & sequence) ;
279
291
TokenTree :: Sequence (
280
292
span,
281
293
Lrc :: new ( SequenceRepetition {
282
294
tts : sequence,
283
295
separator,
284
- op ,
296
+ kleene ,
285
297
num_captures : name_captures,
286
298
} ) ,
287
299
)
@@ -379,28 +391,28 @@ fn parse_sep_and_kleene_op(
379
391
input : & mut Peekable < impl Iterator < Item = tokenstream:: TokenTree > > ,
380
392
span : Span ,
381
393
sess : & ParseSess ,
382
- ) -> ( Option < Token > , KleeneOp ) {
394
+ ) -> ( Option < Token > , KleeneToken ) {
383
395
// We basically look at two token trees here, denoted as #1 and #2 below
384
396
let span = match parse_kleene_op ( input, span) {
385
397
// #1 is a `?`, `+`, or `*` KleeneOp
386
- Ok ( Ok ( ( op, _ ) ) ) => return ( None , op ) ,
398
+ Ok ( Ok ( ( op, span ) ) ) => return ( None , KleeneToken :: new ( op , span ) ) ,
387
399
388
400
// #1 is a separator followed by #2, a KleeneOp
389
401
Ok ( Err ( token) ) => match parse_kleene_op ( input, token. span ) {
390
402
// #2 is the `?` Kleene op, which does not take a separator (error)
391
- Ok ( Ok ( ( KleeneOp :: ZeroOrOne , _ ) ) ) => {
403
+ Ok ( Ok ( ( KleeneOp :: ZeroOrOne , span ) ) ) => {
392
404
// Error!
393
405
sess. span_diagnostic . span_err (
394
406
token. span ,
395
407
"the `?` macro repetition operator does not take a separator" ,
396
408
) ;
397
409
398
410
// Return a dummy
399
- return ( None , KleeneOp :: ZeroOrMore ) ;
411
+ return ( None , KleeneToken :: new ( KleeneOp :: ZeroOrMore , span ) ) ;
400
412
}
401
413
402
414
// #2 is a KleeneOp :D
403
- Ok ( Ok ( ( op, _ ) ) ) => return ( Some ( token) , op ) ,
415
+ Ok ( Ok ( ( op, span ) ) ) => return ( Some ( token) , KleeneToken :: new ( op , span ) ) ,
404
416
405
417
// #2 is a random token or not a token at all :(
406
418
Ok ( Err ( Token { span, .. } ) ) | Err ( span) => span,
@@ -414,5 +426,5 @@ fn parse_sep_and_kleene_op(
414
426
sess. span_diagnostic . span_err ( span, "expected one of: `*`, `+`, or `?`" ) ;
415
427
416
428
// Return a dummy
417
- ( None , KleeneOp :: ZeroOrMore )
429
+ ( None , KleeneToken :: new ( KleeneOp :: ZeroOrMore , span ) )
418
430
}
0 commit comments