@@ -18,6 +18,7 @@ pub(crate) fn dollar_crate(span: Span) -> tt::Ident<Span> {
18
18
// 2. #()* pattern repetition not supported now
19
19
// * But we can do it manually, see `test_quote_derive_copy_hack`
20
20
#[ doc( hidden) ]
21
+ #[ macro_export]
21
22
macro_rules! quote_impl__ {
22
23
( $span: ident) => {
23
24
Vec :: <$crate:: tt:: TokenTree >:: new( )
@@ -27,8 +28,8 @@ macro_rules! quote_impl__ {
27
28
{
28
29
let children = $crate:: builtin:: quote:: __quote!( $span $( $tt) * ) ;
29
30
$crate:: tt:: Subtree {
30
- delimiter: crate :: tt:: Delimiter {
31
- kind: crate :: tt:: DelimiterKind :: $delim,
31
+ delimiter: $ crate:: tt:: Delimiter {
32
+ kind: $ crate:: tt:: DelimiterKind :: $delim,
32
33
open: $span,
33
34
close: $span,
34
35
} ,
@@ -40,9 +41,9 @@ macro_rules! quote_impl__ {
40
41
( @PUNCT ( $span: ident) $first: literal ) => {
41
42
{
42
43
vec![
43
- crate :: tt:: Leaf :: Punct ( crate :: tt:: Punct {
44
+ $ crate:: tt:: Leaf :: Punct ( $ crate:: tt:: Punct {
44
45
char : $first,
45
- spacing: crate :: tt:: Spacing :: Alone ,
46
+ spacing: $ crate:: tt:: Spacing :: Alone ,
46
47
span: $span,
47
48
} ) . into( )
48
49
]
@@ -52,14 +53,14 @@ macro_rules! quote_impl__ {
52
53
( @PUNCT ( $span: ident) $first: literal, $sec: literal ) => {
53
54
{
54
55
vec![
55
- crate :: tt:: Leaf :: Punct ( crate :: tt:: Punct {
56
+ $ crate:: tt:: Leaf :: Punct ( $ crate:: tt:: Punct {
56
57
char : $first,
57
- spacing: crate :: tt:: Spacing :: Joint ,
58
+ spacing: $ crate:: tt:: Spacing :: Joint ,
58
59
span: $span,
59
60
} ) . into( ) ,
60
- crate :: tt:: Leaf :: Punct ( crate :: tt:: Punct {
61
+ $ crate:: tt:: Leaf :: Punct ( $ crate:: tt:: Punct {
61
62
char : $sec,
62
- spacing: crate :: tt:: Spacing :: Alone ,
63
+ spacing: $ crate:: tt:: Spacing :: Alone ,
63
64
span: $span,
64
65
} ) . into( )
65
66
]
@@ -98,7 +99,7 @@ macro_rules! quote_impl__ {
98
99
// Ident
99
100
( $span: ident $tt: ident ) => {
100
101
vec![ {
101
- crate :: tt:: Leaf :: Ident ( crate :: tt:: Ident {
102
+ $ crate:: tt:: Leaf :: Ident ( $ crate:: tt:: Ident {
102
103
sym: intern:: Symbol :: intern( stringify!( $tt) ) ,
103
104
span: $span,
104
105
is_raw: tt:: IdentIsRaw :: No ,
@@ -109,6 +110,7 @@ macro_rules! quote_impl__ {
109
110
// Puncts
110
111
// FIXME: Not all puncts are handled
111
112
( $span: ident -> ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '-' , '>' ) } ;
113
+ ( $span: ident => ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '=' , '>' ) } ;
112
114
( $span: ident & ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '&' ) } ;
113
115
( $span: ident , ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) ',' ) } ;
114
116
( $span: ident : ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) ':' ) } ;
@@ -118,6 +120,9 @@ macro_rules! quote_impl__ {
118
120
( $span: ident < ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '<' ) } ;
119
121
( $span: ident > ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '>' ) } ;
120
122
( $span: ident ! ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '!' ) } ;
123
+ ( $span: ident # ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '#' ) } ;
124
+ ( $span: ident $ ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '$' ) } ;
125
+ ( $span: ident * ) => { $crate:: builtin:: quote:: __quote!( @PUNCT ( $span) '*' ) } ;
121
126
122
127
( $span: ident $first: tt $( $tail: tt) + ) => {
123
128
{
@@ -129,18 +134,19 @@ macro_rules! quote_impl__ {
129
134
}
130
135
} ;
131
136
}
132
- pub ( super ) use quote_impl__ as __quote;
137
+ pub use quote_impl__ as __quote;
133
138
134
139
/// FIXME:
135
140
/// It probably should implement in proc-macro
136
- macro_rules! quote_impl {
141
+ #[ macro_export]
142
+ macro_rules! quote {
137
143
( $span: ident=> $( $tt: tt) * ) => {
138
144
$crate:: builtin:: quote:: IntoTt :: to_subtree( $crate:: builtin:: quote:: __quote!( $span $( $tt) * ) , $span)
139
145
}
140
146
}
141
- pub ( super ) use quote_impl as quote;
147
+ pub ( super ) use quote;
142
148
143
- pub ( crate ) trait IntoTt {
149
+ pub trait IntoTt {
144
150
fn to_subtree ( self , span : Span ) -> crate :: tt:: Subtree ;
145
151
fn to_tokens ( self ) -> Vec < crate :: tt:: TokenTree > ;
146
152
}
@@ -168,7 +174,7 @@ impl IntoTt for crate::tt::Subtree {
168
174
}
169
175
}
170
176
171
- pub ( crate ) trait ToTokenTree {
177
+ pub trait ToTokenTree {
172
178
fn to_token ( self , span : Span ) -> crate :: tt:: TokenTree ;
173
179
}
174
180
0 commit comments