@@ -591,10 +591,32 @@ impl fmt::Display for Literal {
591
591
}
592
592
}
593
593
594
- named ! ( token_stream -> :: TokenStream , map!(
595
- many0!( token_tree) ,
596
- |trees| :: TokenStream :: _new( TokenStream { inner: trees } )
597
- ) ) ;
594
+ fn token_stream ( mut input : Cursor ) -> PResult < :: TokenStream > {
595
+ let mut trees = Vec :: new ( ) ;
596
+ loop {
597
+ let input_no_ws = skip_whitespace ( input) ;
598
+ if input_no_ws. rest . len ( ) == 0 {
599
+ break
600
+ }
601
+ if let Ok ( ( a, comment) ) = doc_comment ( input_no_ws) {
602
+ input = a;
603
+ trees. push ( TokenTree :: Op ( Op :: new ( '#' , Spacing :: Alone ) ) ) ;
604
+ let stream = vec ! [
605
+ TokenTree :: Term ( :: Term :: new( "doc" , :: Span :: call_site( ) ) ) ,
606
+ TokenTree :: Op ( Op :: new( '=' , Spacing :: Alone ) ) ,
607
+ TokenTree :: Literal ( :: Literal :: string( comment) ) ,
608
+ ] ;
609
+ let stream = stream. into_iter ( ) . collect ( ) ;
610
+ trees. push ( TokenTree :: Group ( Group :: new ( Delimiter :: Bracket , stream) ) ) ;
611
+ continue
612
+ }
613
+
614
+ let ( a, tt) = token_tree ( input_no_ws) ?;
615
+ trees. push ( tt) ;
616
+ input = a;
617
+ }
618
+ Ok ( ( input, :: TokenStream :: _new ( TokenStream { inner : trees } ) ) )
619
+ }
598
620
599
621
#[ cfg( not( procmacro2_semver_exempt) ) ]
600
622
fn token_tree ( input : Cursor ) -> PResult < TokenTree > {
@@ -721,8 +743,6 @@ named!(literal_nocapture -> (), alt!(
721
743
float
722
744
|
723
745
int
724
- |
725
- doc_comment
726
746
) ) ;
727
747
728
748
named ! ( string -> ( ) , alt!(
@@ -1146,31 +1166,31 @@ fn op_char(input: Cursor) -> PResult<char> {
1146
1166
}
1147
1167
}
1148
1168
1149
- named ! ( doc_comment -> ( ) , alt!(
1169
+ named ! ( doc_comment -> & str , alt!(
1150
1170
do_parse!(
1151
1171
punct!( "//!" ) >>
1152
- take_until_newline_or_eof!( ) >>
1153
- ( ( ) )
1172
+ s : take_until_newline_or_eof!( ) >>
1173
+ ( s )
1154
1174
)
1155
1175
|
1156
1176
do_parse!(
1157
1177
option!( whitespace) >>
1158
1178
peek!( tag!( "/*!" ) ) >>
1159
- block_comment >>
1160
- ( ( ) )
1179
+ s : block_comment >>
1180
+ ( s )
1161
1181
)
1162
1182
|
1163
1183
do_parse!(
1164
1184
punct!( "///" ) >>
1165
1185
not!( tag!( "/" ) ) >>
1166
- take_until_newline_or_eof!( ) >>
1167
- ( ( ) )
1186
+ s : take_until_newline_or_eof!( ) >>
1187
+ ( s )
1168
1188
)
1169
1189
|
1170
1190
do_parse!(
1171
1191
option!( whitespace) >>
1172
1192
peek!( tuple!( tag!( "/**" ) , not!( tag!( "*" ) ) ) ) >>
1173
- block_comment >>
1174
- ( ( ) )
1193
+ s : block_comment >>
1194
+ ( s )
1175
1195
)
1176
1196
) ) ;
0 commit comments