@@ -42,8 +42,7 @@ pub mod rt {
42
42
pub use ast:: * ;
43
43
pub use parse:: token:: * ;
44
44
pub use parse:: new_parser_from_tts;
45
- pub use codemap:: BytePos ;
46
- pub use codemap:: span;
45
+ pub use codemap:: { BytePos , span, dummy_spanned} ;
47
46
48
47
use print:: pprust;
49
48
use print:: pprust:: { item_to_str, ty_to_str} ;
@@ -119,6 +118,90 @@ pub mod rt {
119
118
}
120
119
}
121
120
121
+ impl ToSource for ast::blk {
122
+ fn to_source(&self, cx: @ext_ctxt) -> ~str {
123
+ pprust::block_to_str(self, cx.parse_sess().interner)
124
+ }
125
+ }
126
+
127
+ impl<'self> ToSource for &'self str {
128
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
129
+ let lit = dummy_spanned(ast::lit_str(@str::from_slice(*self)));
130
+ pprust::lit_to_str(@lit)
131
+ }
132
+ }
133
+
134
+ impl ToSource for int {
135
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
136
+ let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i));
137
+ pprust::lit_to_str(@lit)
138
+ }
139
+ }
140
+
141
+ impl ToSource for i8 {
142
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
143
+ let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i8));
144
+ pprust::lit_to_str(@lit)
145
+ }
146
+ }
147
+
148
+ impl ToSource for i16 {
149
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
150
+ let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i16));
151
+ pprust::lit_to_str(@lit)
152
+ }
153
+ }
154
+
155
+
156
+ impl ToSource for i32 {
157
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
158
+ let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i32));
159
+ pprust::lit_to_str(@lit)
160
+ }
161
+ }
162
+
163
+ impl ToSource for i64 {
164
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
165
+ let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i64));
166
+ pprust::lit_to_str(@lit)
167
+ }
168
+ }
169
+
170
+ impl ToSource for uint {
171
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
172
+ let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u));
173
+ pprust::lit_to_str(@lit)
174
+ }
175
+ }
176
+
177
+ impl ToSource for u8 {
178
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
179
+ let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u8));
180
+ pprust::lit_to_str(@lit)
181
+ }
182
+ }
183
+
184
+ impl ToSource for u16 {
185
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
186
+ let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u16));
187
+ pprust::lit_to_str(@lit)
188
+ }
189
+ }
190
+
191
+ impl ToSource for u32 {
192
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
193
+ let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u32));
194
+ pprust::lit_to_str(@lit)
195
+ }
196
+ }
197
+
198
+ impl ToSource for u64 {
199
+ fn to_source(&self, _cx: @ext_ctxt) -> ~str {
200
+ let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u64));
201
+ pprust::lit_to_str(@lit)
202
+ }
203
+ }
204
+
122
205
// Alas ... we write these out instead. All redundant.
123
206
124
207
impl ToTokens for ast::ident {
@@ -163,6 +246,78 @@ pub mod rt {
163
246
}
164
247
}
165
248
249
+ impl ToTokens for ast::blk {
250
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
251
+ cx.parse_tts(self.to_source(cx))
252
+ }
253
+ }
254
+
255
+ impl<'self> ToTokens for &'self str {
256
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
257
+ cx.parse_tts(self.to_source(cx))
258
+ }
259
+ }
260
+
261
+ impl ToTokens for int {
262
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
263
+ cx.parse_tts(self.to_source(cx))
264
+ }
265
+ }
266
+
267
+ impl ToTokens for i8 {
268
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
269
+ cx.parse_tts(self.to_source(cx))
270
+ }
271
+ }
272
+
273
+ impl ToTokens for i16 {
274
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
275
+ cx.parse_tts(self.to_source(cx))
276
+ }
277
+ }
278
+
279
+ impl ToTokens for i32 {
280
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
281
+ cx.parse_tts(self.to_source(cx))
282
+ }
283
+ }
284
+
285
+ impl ToTokens for i64 {
286
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
287
+ cx.parse_tts(self.to_source(cx))
288
+ }
289
+ }
290
+
291
+ impl ToTokens for uint {
292
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
293
+ cx.parse_tts(self.to_source(cx))
294
+ }
295
+ }
296
+
297
+ impl ToTokens for u8 {
298
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
299
+ cx.parse_tts(self.to_source(cx))
300
+ }
301
+ }
302
+
303
+ impl ToTokens for u16 {
304
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
305
+ cx.parse_tts(self.to_source(cx))
306
+ }
307
+ }
308
+
309
+ impl ToTokens for u32 {
310
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
311
+ cx.parse_tts(self.to_source(cx))
312
+ }
313
+ }
314
+
315
+ impl ToTokens for u64 {
316
+ fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] {
317
+ cx.parse_tts(self.to_source(cx))
318
+ }
319
+ }
320
+
166
321
pub trait ExtParseUtils {
167
322
fn parse_item(&self, s: ~str) -> @ast::item;
168
323
fn parse_expr(&self, s: ~str) -> @ast::expr;
0 commit comments