@@ -15,14 +15,13 @@ pub use self::Lit::*;
15
15
pub use self :: Token :: * ;
16
16
17
17
use ast:: { self } ;
18
- use edition:: Edition ;
19
18
use parse:: ParseSess ;
20
19
use print:: pprust;
21
20
use ptr:: P ;
22
21
use serialize:: { Decodable , Decoder , Encodable , Encoder } ;
23
22
use symbol:: keywords;
24
23
use syntax:: parse:: parse_stream_from_source_str;
25
- use syntax_pos:: { self , hygiene , Span , FileName } ;
24
+ use syntax_pos:: { self , Span , FileName } ;
26
25
use tokenstream:: { TokenStream , TokenTree } ;
27
26
use tokenstream;
28
27
@@ -139,48 +138,6 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool {
139
138
] . contains ( & ident. name )
140
139
}
141
140
142
- pub fn is_path_segment_keyword ( id : ast:: Ident ) -> bool {
143
- id. name == keywords:: Super . name ( ) ||
144
- id. name == keywords:: SelfValue . name ( ) ||
145
- id. name == keywords:: SelfType . name ( ) ||
146
- id. name == keywords:: Extern . name ( ) ||
147
- id. name == keywords:: Crate . name ( ) ||
148
- id. name == keywords:: CrateRoot . name ( ) ||
149
- id. name == keywords:: DollarCrate . name ( )
150
- }
151
-
152
- // We see this identifier in a normal identifier position, like variable name or a type.
153
- // How was it written originally? Did it use the raw form? Let's try to guess.
154
- pub fn is_raw_guess ( ident : ast:: Ident ) -> bool {
155
- ident. name != keywords:: Invalid . name ( ) &&
156
- is_reserved_ident ( ident) && !is_path_segment_keyword ( ident)
157
- }
158
-
159
- // Returns true for reserved identifiers used internally for elided lifetimes,
160
- // unnamed method parameters, crate root module, error recovery etc.
161
- pub fn is_special_ident ( id : ast:: Ident ) -> bool {
162
- id. name <= keywords:: Underscore . name ( )
163
- }
164
-
165
- /// Returns `true` if the token is a keyword used in the language.
166
- pub fn is_used_keyword ( id : ast:: Ident ) -> bool {
167
- id. name >= keywords:: As . name ( ) && id. name <= keywords:: While . name ( )
168
- }
169
-
170
- /// Returns `true` if the token is a keyword reserved for possible future use.
171
- pub fn is_unused_keyword ( id : ast:: Ident ) -> bool {
172
- let edition = || id. span . ctxt ( ) . outer ( ) . expn_info ( ) . map_or_else ( || hygiene:: default_edition ( ) ,
173
- |einfo| einfo. callee . edition ) ;
174
- id. name >= keywords:: Abstract . name ( ) && id. name <= keywords:: Yield . name ( ) ||
175
- id. name == keywords:: Proc . name ( ) && edition ( ) == Edition :: Edition2015 ||
176
- id. name == keywords:: Async . name ( ) && edition ( ) == Edition :: Edition2018
177
- }
178
-
179
- /// Returns `true` if the token is either a special identifier or a keyword.
180
- pub fn is_reserved_ident ( id : ast:: Ident ) -> bool {
181
- is_special_ident ( id) || is_used_keyword ( id) || is_unused_keyword ( id)
182
- }
183
-
184
141
#[ derive( Clone , RustcEncodable , RustcDecodable , PartialEq , Eq , Hash , Debug ) ]
185
142
pub enum Token {
186
143
/* Expression-operator symbols. */
@@ -256,7 +213,7 @@ impl Token {
256
213
257
214
/// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary.
258
215
pub fn from_ast_ident ( ident : ast:: Ident ) -> Token {
259
- Ident ( ident, is_raw_guess ( ident ) )
216
+ Ident ( ident, ident . is_raw_guess ( ) )
260
217
}
261
218
262
219
/// Returns `true` if the token starts with '>'.
@@ -436,7 +393,7 @@ impl Token {
436
393
437
394
pub fn is_path_segment_keyword ( & self ) -> bool {
438
395
match self . ident ( ) {
439
- Some ( ( id, false ) ) => is_path_segment_keyword ( id ) ,
396
+ Some ( ( id, false ) ) => id . is_path_segment_keyword ( ) ,
440
397
_ => false ,
441
398
}
442
399
}
@@ -445,31 +402,31 @@ impl Token {
445
402
// unnamed method parameters, crate root module, error recovery etc.
446
403
pub fn is_special_ident ( & self ) -> bool {
447
404
match self . ident ( ) {
448
- Some ( ( id, false ) ) => is_special_ident ( id ) ,
405
+ Some ( ( id, false ) ) => id . is_special ( ) ,
449
406
_ => false ,
450
407
}
451
408
}
452
409
453
410
/// Returns `true` if the token is a keyword used in the language.
454
411
pub fn is_used_keyword ( & self ) -> bool {
455
412
match self . ident ( ) {
456
- Some ( ( id, false ) ) => is_used_keyword ( id ) ,
413
+ Some ( ( id, false ) ) => id . is_used_keyword ( ) ,
457
414
_ => false ,
458
415
}
459
416
}
460
417
461
418
/// Returns `true` if the token is a keyword reserved for possible future use.
462
419
pub fn is_unused_keyword ( & self ) -> bool {
463
420
match self . ident ( ) {
464
- Some ( ( id, false ) ) => is_unused_keyword ( id ) ,
421
+ Some ( ( id, false ) ) => id . is_unused_keyword ( ) ,
465
422
_ => false ,
466
423
}
467
424
}
468
425
469
426
/// Returns `true` if the token is either a special identifier or a keyword.
470
427
pub fn is_reserved_ident ( & self ) -> bool {
471
428
match self . ident ( ) {
472
- Some ( ( id, false ) ) => is_reserved_ident ( id ) ,
429
+ Some ( ( id, false ) ) => id . is_reserved ( ) ,
473
430
_ => false ,
474
431
}
475
432
}
0 commit comments