@@ -19,8 +19,8 @@ use rustc_span::hygiene::ExpnKind;
1919use rustc_span:: symbol:: { self , kw, sym, Symbol } ;
2020use rustc_span:: { BytePos , FileName , MultiSpan , Pos , RealFileName , SourceFile , Span } ;
2121
22- use pm:: bridge:: { server, TokenTree } ;
23- use pm:: { Delimiter , Level , LineColumn , Spacing } ;
22+ use pm:: bridge:: { server, Punct , TokenTree } ;
23+ use pm:: { Delimiter , Level , LineColumn } ;
2424use std:: ops:: Bound ;
2525use std:: { ascii, panic} ;
2626
@@ -55,7 +55,7 @@ impl ToInternal<token::DelimToken> for Delimiter {
5555}
5656
5757impl FromInternal < ( TreeAndSpacing , & ' _ mut Vec < Self > , & mut Rustc < ' _ > ) >
58- for TokenTree < Group , Punct , Ident , Literal >
58+ for TokenTree < Span , Group , Ident , Literal >
5959{
6060 fn from_internal (
6161 ( ( tree, spacing) , stack, rustc) : ( TreeAndSpacing , & mut Vec < Self > , & mut Rustc < ' _ > ) ,
@@ -84,16 +84,16 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
8484 }
8585 macro_rules! op {
8686 ( $a: expr) => {
87- tt!( Punct :: new ( $a, joint) )
87+ tt!( Punct { ch : $a, joint } )
8888 } ;
8989 ( $a: expr, $b: expr) => { {
90- stack. push( tt!( Punct :: new ( $b, joint) ) ) ;
91- tt!( Punct :: new ( $a, true ) )
90+ stack. push( tt!( Punct { ch : $b, joint } ) ) ;
91+ tt!( Punct { ch : $a, joint : true } )
9292 } } ;
9393 ( $a: expr, $b: expr, $c: expr) => { {
94- stack. push( tt!( Punct :: new ( $c, joint) ) ) ;
95- stack. push( tt!( Punct :: new ( $b, true ) ) ) ;
96- tt!( Punct :: new ( $a, true ) )
94+ stack. push( tt!( Punct { ch : $c, joint } ) ) ;
95+ stack. push( tt!( Punct { ch : $b, joint : true } ) ) ;
96+ tt!( Punct { ch : $a, joint : true } )
9797 } } ;
9898 }
9999
@@ -151,7 +151,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
151151 Lifetime ( name) => {
152152 let ident = symbol:: Ident :: new ( name, span) . without_first_quote ( ) ;
153153 stack. push ( tt ! ( Ident :: new( rustc. sess, ident. name, false ) ) ) ;
154- tt ! ( Punct :: new ( '\'' , true ) )
154+ tt ! ( Punct { ch : '\'' , joint : true } )
155155 }
156156 Literal ( lit) => tt ! ( Literal { lit } ) ,
157157 DocComment ( _, attr_style, data) => {
@@ -174,9 +174,9 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
174174 flatten : false ,
175175 } ) ) ;
176176 if attr_style == ast:: AttrStyle :: Inner {
177- stack. push ( tt ! ( Punct :: new ( '!' , false ) ) ) ;
177+ stack. push ( tt ! ( Punct { ch : '!' , joint : false } ) ) ;
178178 }
179- tt ! ( Punct :: new ( '#' , false ) )
179+ tt ! ( Punct { ch : '#' , joint : false } )
180180 }
181181
182182 Interpolated ( nt) => {
@@ -199,7 +199,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
199199 }
200200}
201201
202- impl ToInternal < TokenStream > for TokenTree < Group , Punct , Ident , Literal > {
202+ impl ToInternal < TokenStream > for TokenTree < Span , Group , Ident , Literal > {
203203 fn to_internal ( self ) -> TokenStream {
204204 use rustc_ast:: token:: * ;
205205
@@ -295,27 +295,6 @@ pub struct Group {
295295 flatten : bool ,
296296}
297297
298- #[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
299- pub struct Punct {
300- ch : char ,
301- // NB. not using `Spacing` here because it doesn't implement `Hash`.
302- joint : bool ,
303- span : Span ,
304- }
305-
306- impl Punct {
307- fn new ( ch : char , joint : bool , span : Span ) -> Punct {
308- const LEGAL_CHARS : & [ char ] = & [
309- '=' , '<' , '>' , '!' , '~' , '+' , '-' , '*' , '/' , '%' , '^' , '&' , '|' , '@' , '.' , ',' , ';' ,
310- ':' , '#' , '$' , '?' , '\'' ,
311- ] ;
312- if !LEGAL_CHARS . contains ( & ch) {
313- panic ! ( "unsupported character `{:?}`" , ch)
314- }
315- Punct { ch, joint, span }
316- }
317- }
318-
319298#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
320299pub struct Ident {
321300 sym : Symbol ,
@@ -393,7 +372,6 @@ impl server::Types for Rustc<'_> {
393372 type FreeFunctions = FreeFunctions ;
394373 type TokenStream = TokenStream ;
395374 type Group = Group ;
396- type Punct = Punct ;
397375 type Ident = Ident ;
398376 type Literal = Literal ;
399377 type SourceFile = Lrc < SourceFile > ;
@@ -425,14 +403,14 @@ impl server::TokenStream for Rustc<'_> {
425403 }
426404 fn from_token_tree (
427405 & mut self ,
428- tree : TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > ,
406+ tree : TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > ,
429407 ) -> Self :: TokenStream {
430408 tree. to_internal ( )
431409 }
432410 fn concat_trees (
433411 & mut self ,
434412 base : Option < Self :: TokenStream > ,
435- trees : Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > ,
413+ trees : Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > ,
436414 ) -> Self :: TokenStream {
437415 let mut builder = tokenstream:: TokenStreamBuilder :: new ( ) ;
438416 if let Some ( base) = base {
@@ -460,7 +438,7 @@ impl server::TokenStream for Rustc<'_> {
460438 fn into_iter (
461439 & mut self ,
462440 stream : Self :: TokenStream ,
463- ) -> Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > {
441+ ) -> Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > {
464442 // XXX: This is a raw port of the previous approach, and can probably be
465443 // optimized.
466444 let mut cursor = stream. trees ( ) ;
@@ -521,28 +499,6 @@ impl server::Group for Rustc<'_> {
521499 }
522500}
523501
524- impl server:: Punct for Rustc < ' _ > {
525- fn new ( & mut self , ch : char , spacing : Spacing ) -> Self :: Punct {
526- Punct :: new ( ch, spacing == Spacing :: Joint , server:: Context :: call_site ( self ) )
527- }
528- fn as_char ( & mut self , punct : Self :: Punct ) -> char {
529- punct. ch
530- }
531- fn spacing ( & mut self , punct : Self :: Punct ) -> Spacing {
532- if punct. joint {
533- Spacing :: Joint
534- } else {
535- Spacing :: Alone
536- }
537- }
538- fn span ( & mut self , punct : Self :: Punct ) -> Self :: Span {
539- punct. span
540- }
541- fn with_span ( & mut self , punct : Self :: Punct , span : Self :: Span ) -> Self :: Punct {
542- Punct { span, ..punct }
543- }
544- }
545-
546502impl server:: Ident for Rustc < ' _ > {
547503 fn new ( & mut self , string : & str , span : Self :: Span , is_raw : bool ) -> Self :: Ident {
548504 Ident :: new ( self . sess , Symbol :: intern ( string) , is_raw, span)
0 commit comments