Skip to content

Commit e293026

Browse files
committed
auto merge of #9768 : pnkfelix/rust/fsk-fix-issue-9762, r=bstrie
r? anyone Add bindings for start and ends of keyword ranges; use bindings in match arms. Also, fixed latent bug that inspired this change: the pattern in `is_any_keyword` had not been updated to match the new range of reserved keyword identifiers. (I briefly tried to expose the latent bug, but `is_any_keyword` is currently only called in contexts where a failure of this kind merely causes a bit more fruitless compilation before `check_reserved_keywords` is called by the parser, which correctly tags `sizeof` as reserved.)
2 parents 7ba8033 + 580adc9 commit e293026

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

src/libsyntax/parse/token.rs

+40-11
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub mod special_idents {
326326
pub static unary_minus_fn : Ident = Ident { name: 6, ctxt: 0}; // apparently unused?
327327
pub static clownshoes_extensions : Ident = Ident { name: 7, ctxt: 0};
328328

329-
pub static self_ : Ident = Ident { name: 8, ctxt: 0}; // 'self'
329+
pub static self_ : Ident = Ident { name: super::SELF_KEYWORD_NAME, ctxt: 0}; // 'self'
330330

331331
/* for matcher NTs */
332332
// none of these appear to be used, but perhaps references to
@@ -352,7 +352,7 @@ pub mod special_idents {
352352
pub static main : Ident = Ident { name: 24, ctxt: 0};
353353
pub static opaque : Ident = Ident { name: 25, ctxt: 0};
354354
pub static blk : Ident = Ident { name: 26, ctxt: 0};
355-
pub static statik : Ident = Ident { name: 27, ctxt: 0};
355+
pub static statik : Ident = Ident { name: super::STATIC_KEYWORD_NAME, ctxt: 0};
356356
pub static clownshoes_foreign_mod: Ident = Ident { name: 28, ctxt: 0};
357357
pub static unnamed_field: Ident = Ident { name: 29, ctxt: 0};
358358
pub static c_abi: Ident = Ident { name: 30, ctxt: 0}; // apparently unused?
@@ -414,8 +414,9 @@ pub type ident_interner = StrInterner;
414414

415415
// return a fresh interner, preloaded with special identifiers.
416416
fn mk_fresh_ident_interner() -> @ident_interner {
417-
// the indices here must correspond to the numbers in
418-
// special_idents.
417+
// The indices here must correspond to the numbers in
418+
// special_idents, in Keyword to_ident(), and in static
419+
// constants below.
419420
let init_vec = ~[
420421
"_", // 0
421422
"anon", // 1
@@ -473,8 +474,8 @@ fn mk_fresh_ident_interner() -> @ident_interner {
473474
"pub", // 52
474475
"ref", // 53
475476
"return", // 54
476-
"static", // 27 -- also a special ident
477-
"self", // 8 -- also a special ident
477+
"static", // 27 -- also a special ident (prefill de-dupes)
478+
"self", // 8 -- also a special ident (prefill de-dupes)
478479
"struct", // 55
479480
"super", // 56
480481
"true", // 57
@@ -498,6 +499,32 @@ fn mk_fresh_ident_interner() -> @ident_interner {
498499
@interner::StrInterner::prefill(init_vec)
499500
}
500501

502+
// NOTE remove stage0 pub'ed special cases after next snapshot.
503+
#[cfg(stage0)]
504+
pub static SELF_KEYWORD_NAME: uint = 8;
505+
#[cfg(not(stage0))]
506+
static SELF_KEYWORD_NAME: uint = 8;
507+
#[cfg(stage0)]
508+
pub static STATIC_KEYWORD_NAME: uint = 27;
509+
#[cfg(not(stage0))]
510+
static STATIC_KEYWORD_NAME: uint = 27;
511+
#[cfg(stage0)]
512+
pub static STRICT_KEYWORD_START: uint = 32;
513+
#[cfg(not(stage0))]
514+
static STRICT_KEYWORD_START: uint = 32;
515+
#[cfg(stage0)]
516+
pub static STRICT_KEYWORD_FINAL: uint = 64;
517+
#[cfg(not(stage0))]
518+
static STRICT_KEYWORD_FINAL: uint = 64;
519+
#[cfg(stage0)]
520+
pub static RESERVED_KEYWORD_START: uint = 65;
521+
#[cfg(not(stage0))]
522+
static RESERVED_KEYWORD_START: uint = 65;
523+
#[cfg(stage0)]
524+
pub static RESERVED_KEYWORD_FINAL: uint = 71;
525+
#[cfg(not(stage0))]
526+
static RESERVED_KEYWORD_FINAL: uint = 71;
527+
501528
// if an interner exists in TLS, return it. Otherwise, prepare a
502529
// fresh one.
503530
pub fn get_ident_interner() -> @ident_interner {
@@ -675,8 +702,8 @@ pub mod keywords {
675702
Pub => Ident { name: 52, ctxt: 0 },
676703
Ref => Ident { name: 53, ctxt: 0 },
677704
Return => Ident { name: 54, ctxt: 0 },
678-
Static => Ident { name: 27, ctxt: 0 },
679-
Self => Ident { name: 8, ctxt: 0 },
705+
Static => Ident { name: super::STATIC_KEYWORD_NAME, ctxt: 0 },
706+
Self => Ident { name: super::SELF_KEYWORD_NAME, ctxt: 0 },
680707
Struct => Ident { name: 55, ctxt: 0 },
681708
Super => Ident { name: 56, ctxt: 0 },
682709
True => Ident { name: 57, ctxt: 0 },
@@ -709,7 +736,8 @@ pub fn is_keyword(kw: keywords::Keyword, tok: &Token) -> bool {
709736
pub fn is_any_keyword(tok: &Token) -> bool {
710737
match *tok {
711738
token::IDENT(sid, false) => match sid.name {
712-
8 | 27 | 32 .. 70 => true,
739+
SELF_KEYWORD_NAME | STATIC_KEYWORD_NAME |
740+
STRICT_KEYWORD_START .. RESERVED_KEYWORD_FINAL => true,
713741
_ => false,
714742
},
715743
_ => false
@@ -719,7 +747,8 @@ pub fn is_any_keyword(tok: &Token) -> bool {
719747
pub fn is_strict_keyword(tok: &Token) -> bool {
720748
match *tok {
721749
token::IDENT(sid, false) => match sid.name {
722-
8 | 27 | 32 .. 64 => true,
750+
SELF_KEYWORD_NAME | STATIC_KEYWORD_NAME |
751+
STRICT_KEYWORD_START .. STRICT_KEYWORD_FINAL => true,
723752
_ => false,
724753
},
725754
_ => false,
@@ -729,7 +758,7 @@ pub fn is_strict_keyword(tok: &Token) -> bool {
729758
pub fn is_reserved_keyword(tok: &Token) -> bool {
730759
match *tok {
731760
token::IDENT(sid, false) => match sid.name {
732-
65 .. 71 => true,
761+
RESERVED_KEYWORD_START .. RESERVED_KEYWORD_FINAL => true,
733762
_ => false,
734763
},
735764
_ => false,

0 commit comments

Comments
 (0)