File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ pub enum TokenKind {
66
66
Ident ,
67
67
/// "r#ident"
68
68
RawIdent ,
69
+ /// "k#ident"
70
+ /// Unstable feature handling is done in rustc_parse/src/lexer/mod.rs
71
+ RawKeyword ,
69
72
/// "12_u8", "1.0e-40", "b"123"". See `LiteralKind` for more details.
70
73
Literal { kind : LiteralKind , suffix_start : usize } ,
71
74
/// "'a"
@@ -361,6 +364,9 @@ impl Cursor<'_> {
361
364
_ => self . ident ( ) ,
362
365
} ,
363
366
367
+ // Raw keyword
368
+ 'k' if self . first ( ) == '#' && is_id_start ( self . second ( ) ) => self . raw_keyword ( ) ,
369
+
364
370
// Identifier (this should be checked after other variant that can
365
371
// start as identifier).
366
372
c if is_id_start ( c) => self . ident ( ) ,
@@ -487,6 +493,15 @@ impl Cursor<'_> {
487
493
RawIdent
488
494
}
489
495
496
+ fn raw_keyword ( & mut self ) -> TokenKind {
497
+ debug_assert ! ( self . prev( ) == 'k' && self . first( ) == '#' && is_id_start( self . second( ) ) ) ;
498
+ // Eat "#" symbol.
499
+ self . bump ( ) ;
500
+ // Eat the identifier part of the keyword.
501
+ self . eat_identifier ( ) ;
502
+ RawKeyword
503
+ }
504
+
490
505
fn ident ( & mut self ) -> TokenKind {
491
506
debug_assert ! ( is_id_start( self . prev( ) ) ) ;
492
507
// Start is already eaten, eat the rest of identifier.
Original file line number Diff line number Diff line change @@ -187,6 +187,25 @@ impl<'a> StringReader<'a> {
187
187
}
188
188
token:: Ident ( sym, is_raw_ident)
189
189
}
190
+ rustc_lexer:: TokenKind :: RawKeyword => {
191
+ let span = self . mk_sp ( start, self . pos ) ;
192
+ self . sess
193
+ . span_diagnostic
194
+ . struct_span_err ( span, "raw keyword syntax is reserved for future use" )
195
+ // With whitespace, it tokenizes as three tokens, just like before this reservation.
196
+ . span_suggestion (
197
+ span,
198
+ "insert a whitespace" ,
199
+ format ! ( "k #{}" , self . str_from( start + BytePos ( 2 ) ) ) ,
200
+ Applicability :: MachineApplicable ,
201
+ )
202
+ . emit ( ) ;
203
+
204
+ let sym = nfc_normalize ( self . str_from ( start + BytePos ( 2 ) ) ) ;
205
+ // For recovery, treat it as a raw ident.
206
+ // FIXME: Add a flag to Ident to mark it as a raw keyword.
207
+ token:: Ident ( sym, true )
208
+ }
190
209
rustc_lexer:: TokenKind :: Literal { kind, suffix_start } => {
191
210
let suffix_start = start + BytePos ( suffix_start as u32 ) ;
192
211
let ( kind, symbol) = self . cook_lexer_literal ( start, suffix_start, kind) ;
Original file line number Diff line number Diff line change @@ -408,6 +408,8 @@ impl<'a> Classifier<'a> {
408
408
c => c,
409
409
} ,
410
410
TokenKind :: RawIdent => Class :: Ident ,
411
+ //TODO How do I test this?
412
+ TokenKind :: RawKeyword => Class :: KeyWord ,
411
413
TokenKind :: Lifetime { .. } => Class :: Lifetime ,
412
414
} ;
413
415
// Anything that didn't return above is the simple case where we the
You can’t perform that action at this time.
0 commit comments