Skip to content

Commit 98ac8d4

Browse files
committed
syntax: Clean up the bad_expr_word functions
1 parent 7ee90cc commit 98ac8d4

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

src/librustsyntax/parse/common.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn parse_path_list_ident(p: parser) -> ast::path_list_ident {
4343
}
4444

4545
fn parse_value_ident(p: parser) -> ast::ident {
46-
check_bad_word(p);
46+
check_bad_expr_word(p);
4747
ret parse_ident(p);
4848
}
4949

@@ -87,11 +87,19 @@ fn expect_keyword(p: parser, word: str) {
8787
}
8888
}
8989

90-
fn check_bad_word(p: parser) {
91-
if token::is_bad_expr_word(p.token, p.bad_expr_words,
92-
*p.reader.interner) {
90+
fn is_bad_expr_word(p: parser, word: str) -> bool {
91+
p.bad_expr_words.contains_key(word)
92+
}
93+
94+
fn check_bad_expr_word(p: parser) {
95+
alt p.token {
96+
token::IDENT(_, false) {
9397
let w = token_to_str(p.reader, p.token);
94-
p.fatal("found " + w + " in expression position");
98+
if is_bad_expr_word(p, w) {
99+
p.fatal("found `" + w + "` in expression position");
100+
}
101+
}
102+
_ { }
95103
}
96104
}
97105

src/librustsyntax/parse/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fn parse_path(p: parser) -> @ast::path {
543543
fn parse_value_path(p: parser) -> @ast::path {
544544
let pt = parse_path(p);
545545
let last_word = vec::last(pt.idents);
546-
if p.bad_expr_words.contains_key(last_word) {
546+
if is_bad_expr_word(p, last_word) {
547547
p.fatal("found " + last_word + " in expression position");
548548
}
549549
pt
@@ -802,7 +802,7 @@ fn parse_bottom_expr(p: parser) -> pexpr {
802802
} else if p.token == token::MOD_SEP ||
803803
is_ident(p.token) && !is_keyword(p, "true") &&
804804
!is_keyword(p, "false") {
805-
check_bad_word(p);
805+
check_bad_expr_word(p);
806806
let pth = parse_path_and_ty_param_substs(p, true);
807807
hi = pth.span.hi;
808808
ex = ast::expr_path(pth);
@@ -1370,7 +1370,7 @@ fn parse_pat(p: parser) -> @ast::pat {
13701370
p.bump();
13711371
subpat = parse_pat(p);
13721372
} else {
1373-
if p.bad_expr_words.contains_key(fieldname) {
1373+
if is_bad_expr_word(p, fieldname) {
13741374
p.fatal("found " + fieldname + " in binding position");
13751375
}
13761376
subpat = @{id: p.get_id(),
@@ -2098,7 +2098,7 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item {
20982098
let mut variants: [ast::variant] = [];
20992099
// Newtype syntax
21002100
if p.token == token::EQ {
2101-
if p.bad_expr_words.contains_key(id) {
2101+
if is_bad_expr_word(p, id) {
21022102
p.fatal("found " + id + " in enum constructor position");
21032103
}
21042104
p.bump();

src/librustsyntax/parse/token.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,6 @@ fn is_bar(t: token::token) -> bool {
200200
alt t { token::BINOP(token::OR) | token::OROR { true } _ { false } }
201201
}
202202

203-
fn is_bad_expr_word(t: token,
204-
bad_expr_words: hashmap<str, ()>,
205-
in: interner<str>) -> bool {
206-
alt t {
207-
token::IDENT(_, false) {
208-
bad_expr_words.contains_key(to_str(in, t))
209-
}
210-
_ { false }
211-
}
212-
}
213-
214203
#[doc = "
215204
All the valid words that have meaning in the Rust language. Some of these are
216205
nonetheless valid as identifiers becasue they are unambiguous.

0 commit comments

Comments
 (0)