@@ -56,6 +56,8 @@ macro_rules! with_api {
5656 fn drop( $self: $S:: FreeFunctions ) ;
5757 fn track_env_var( var: & str , value: Option <& str >) ;
5858 fn track_path( path: & str ) ;
59+ fn literal_from_str( s: & str ) -> Result <Literal <$S:: Span , $S:: Symbol >, ( ) >;
60+ fn literal_subspan( lit: Literal <$S:: Span , $S:: Symbol >, start: Bound <usize >, end: Bound <usize >) -> Option <$S:: Span >;
5961 } ,
6062 TokenStream {
6163 fn drop( $self: $S:: TokenStream ) ;
@@ -65,43 +67,19 @@ macro_rules! with_api {
6567 fn from_str( src: & str ) -> $S:: TokenStream ;
6668 fn to_string( $self: & $S:: TokenStream ) -> String ;
6769 fn from_token_tree(
68- tree: TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol , $S :: Literal >,
70+ tree: TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol >,
6971 ) -> $S:: TokenStream ;
7072 fn concat_trees(
7173 base: Option <$S:: TokenStream >,
72- trees: Vec <TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol , $S :: Literal >>,
74+ trees: Vec <TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol >>,
7375 ) -> $S:: TokenStream ;
7476 fn concat_streams(
7577 base: Option <$S:: TokenStream >,
7678 streams: Vec <$S:: TokenStream >,
7779 ) -> $S:: TokenStream ;
7880 fn into_trees(
7981 $self: $S:: TokenStream
80- ) -> Vec <TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol , $S:: Literal >>;
81- } ,
82- Literal {
83- fn drop( $self: $S:: Literal ) ;
84- fn clone( $self: & $S:: Literal ) -> $S:: Literal ;
85- fn from_str( s: & str ) -> Result <$S:: Literal , ( ) >;
86- fn to_string( $self: & $S:: Literal ) -> String ;
87- fn debug_kind( $self: & $S:: Literal ) -> String ;
88- fn symbol( $self: & $S:: Literal ) -> String ;
89- fn suffix( $self: & $S:: Literal ) -> Option <String >;
90- fn integer( n: & str ) -> $S:: Literal ;
91- fn typed_integer( n: & str , kind: & str ) -> $S:: Literal ;
92- fn float( n: & str ) -> $S:: Literal ;
93- fn f32 ( n: & str ) -> $S:: Literal ;
94- fn f64 ( n: & str ) -> $S:: Literal ;
95- fn string( string: & str ) -> $S:: Literal ;
96- fn character( ch: char ) -> $S:: Literal ;
97- fn byte_string( bytes: & [ u8 ] ) -> $S:: Literal ;
98- fn span( $self: & $S:: Literal ) -> $S:: Span ;
99- fn set_span( $self: & mut $S:: Literal , span: $S:: Span ) ;
100- fn subspan(
101- $self: & $S:: Literal ,
102- start: Bound <usize >,
103- end: Bound <usize >,
104- ) -> Option <$S:: Span >;
82+ ) -> Vec <TokenTree <$S:: TokenStream , $S:: Span , $S:: Symbol >>;
10583 } ,
10684 SourceFile {
10785 fn drop( $self: $S:: SourceFile ) ;
@@ -332,6 +310,7 @@ mark_noop! {
332310 u8 ,
333311 usize ,
334312 Delimiter ,
313+ LitKind ,
335314 Level ,
336315 LineColumn ,
337316 Spacing ,
@@ -361,6 +340,33 @@ rpc_encode_decode!(
361340 }
362341) ;
363342
343+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
344+ pub enum LitKind {
345+ Byte ,
346+ Char ,
347+ Integer ,
348+ Float ,
349+ Str ,
350+ StrRaw ( u8 ) ,
351+ ByteStr ,
352+ ByteStrRaw ( u8 ) ,
353+ Err ,
354+ }
355+
356+ rpc_encode_decode ! (
357+ enum LitKind {
358+ Byte ,
359+ Char ,
360+ Integer ,
361+ Float ,
362+ Str ,
363+ StrRaw ( n) ,
364+ ByteStr ,
365+ ByteStrRaw ( n) ,
366+ Err ,
367+ }
368+ ) ;
369+
364370macro_rules! mark_compound {
365371 ( struct $name: ident <$( $T: ident) ,+> { $( $field: ident) ,* $( , ) ? } ) => {
366372 impl <$( $T: Mark ) ,+> Mark for $name <$( $T) ,+> {
@@ -477,16 +483,26 @@ pub struct Ident<Span, Symbol> {
477483
478484compound_traits ! ( struct Ident <Span , Symbol > { sym, is_raw, span } ) ;
479485
486+ #[ derive( Clone , Eq , PartialEq ) ]
487+ pub struct Literal < Span , Symbol > {
488+ pub kind : LitKind ,
489+ pub symbol : Symbol ,
490+ pub suffix : Option < Symbol > ,
491+ pub span : Span ,
492+ }
493+
494+ compound_traits ! ( struct Literal <Sp , Sy > { kind, symbol, suffix, span } ) ;
495+
480496#[ derive( Clone ) ]
481- pub enum TokenTree < TokenStream , Span , Symbol , Literal > {
497+ pub enum TokenTree < TokenStream , Span , Symbol > {
482498 Group ( Group < TokenStream , Span > ) ,
483499 Punct ( Punct < Span > ) ,
484500 Ident ( Ident < Span , Symbol > ) ,
485- Literal ( Literal ) ,
501+ Literal ( Literal < Span , Symbol > ) ,
486502}
487503
488504compound_traits ! (
489- enum TokenTree <TokenStream , Span , Symbol , Literal > {
505+ enum TokenTree <TokenStream , Span , Symbol > {
490506 Group ( tt) ,
491507 Punct ( tt) ,
492508 Ident ( tt) ,
0 commit comments