@@ -316,6 +316,17 @@ pub fn is_bar(t: &Token) -> bool {
316
316
match * t { BINOP ( OR ) | OROR => true , _ => false }
317
317
}
318
318
319
+ // Get the first "argument"
320
+ macro_rules! first {
321
+ ( $first: expr, $( $remainder: expr, ) * ) => ( $first )
322
+ }
323
+
324
+ // Get the last "argument" (has to be done recursively to avoid phoney local ambiguity error)
325
+ macro_rules! last {
326
+ ( $first: expr, $( $remainder: expr, ) + ) => ( last!( $( $remainder, ) + ) ) ;
327
+ ( $first: expr, ) => ( $first )
328
+ }
329
+
319
330
// In this macro, there is the requirement that the name (the number) must be monotonically
320
331
// increasing by one in the special identifiers, starting at 0; the same holds for the keywords,
321
332
// except starting from the next number instead of zero, and with the additional exception that
@@ -329,9 +340,17 @@ macro_rules! declare_special_idents_and_keywords {(
329
340
}
330
341
331
342
pub mod keywords {
332
- $( ( $k_name: expr, $k_variant: ident, $k_str: expr) ; ) *
343
+ ' strict:
344
+ $( ( $sk_name: expr, $sk_variant: ident, $sk_str: expr) ; ) *
345
+ ' reserved:
346
+ $( ( $rk_name: expr, $rk_variant: ident, $rk_str: expr) ; ) *
333
347
}
334
348
) => {
349
+ static STRICT_KEYWORD_START : Name = first!( $( $sk_name, ) * ) ;
350
+ static STRICT_KEYWORD_FINAL : Name = last!( $( $sk_name, ) * ) ;
351
+ static RESERVED_KEYWORD_START : Name = first!( $( $rk_name, ) * ) ;
352
+ static RESERVED_KEYWORD_FINAL : Name = last!( $( $rk_name, ) * ) ;
353
+
335
354
pub mod special_idents {
336
355
use ast:: Ident ;
337
356
$( pub static $si_static: Ident = Ident { name: $si_name, ctxt: 0 } ; ) *
@@ -348,13 +367,15 @@ macro_rules! declare_special_idents_and_keywords {(
348
367
use ast:: Ident ;
349
368
350
369
pub enum Keyword {
351
- $( $k_variant, ) *
370
+ $( $sk_variant, ) *
371
+ $( $rk_variant, ) *
352
372
}
353
373
354
374
impl Keyword {
355
375
pub fn to_ident( & self ) -> Ident {
356
376
match * self {
357
- $( $k_variant => Ident { name: $k_name, ctxt: 0 } , ) *
377
+ $( $sk_variant => Ident { name: $sk_name, ctxt: 0 } , ) *
378
+ $( $rk_variant => Ident { name: $rk_name, ctxt: 0 } , ) *
358
379
}
359
380
}
360
381
}
@@ -366,20 +387,17 @@ macro_rules! declare_special_idents_and_keywords {(
366
387
// constants below.
367
388
let init_vec = ~[
368
389
$( $si_str, ) *
369
- $( $k_str, ) *
390
+ $( $sk_str, ) *
391
+ $( $rk_str, ) *
370
392
] ;
371
393
372
394
@interner:: StrInterner :: prefill( init_vec)
373
395
}
374
396
} }
375
397
376
- // If modifying the numbers below , remember to modify these as appropriate
398
+ // If the special idents get renumbered , remember to modify these two as appropriate
377
399
static SELF_KEYWORD_NAME : Name = 3 ;
378
400
static STATIC_KEYWORD_NAME : Name = 10 ;
379
- static STRICT_KEYWORD_START : Name = 14 ;
380
- static STRICT_KEYWORD_FINAL : Name = 47 ;
381
- static RESERVED_KEYWORD_START : Name = 48 ;
382
- static RESERVED_KEYWORD_FINAL : Name = 54 ;
383
401
384
402
declare_special_idents_and_keywords ! {
385
403
pub mod special_idents {
@@ -409,7 +427,7 @@ declare_special_idents_and_keywords! {
409
427
pub mod keywords {
410
428
// These ones are variants of the Keyword enum
411
429
412
- // Strict keywords
430
+ ' strict :
413
431
( 14 , As , "as" ) ;
414
432
( 15 , Break , "break" ) ;
415
433
( 16 , Const , "const" ) ;
@@ -448,7 +466,7 @@ declare_special_idents_and_keywords! {
448
466
( 46 , Continue , "continue" ) ;
449
467
( 47 , Proc , "proc" ) ;
450
468
451
- // Reserved keywords
469
+ ' reserved :
452
470
( 48 , Alignof , "alignof" ) ;
453
471
( 49 , Be , "be" ) ;
454
472
( 50 , Offsetof , "offsetof" ) ;
0 commit comments