Skip to content

Commit b269ce2

Browse files
committed
auto merge of #5255 : jbclements/rust/remove-parse-value-ident, r=graydon
After the removal of the "restricted keyword" feature in 0c82c00 , there's no longer any difference between parse_ident() and parse_value_ident(), and therefore no difference between parse parse_path_without_tps() and parse_value_path(). I've collapsed all of these, removing the redundant functions and eliminating the need for two higher-order arguments.
2 parents 95c0747 + 8bb537e commit b269ce2

File tree

4 files changed

+21
-40
lines changed

4 files changed

+21
-40
lines changed

src/libsyntax/ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ pub struct Lifetime {
105105
ident: ident
106106
}
107107
108+
// a "Path" is essentially Rust's notion of a name;
109+
// for instance: core::cmp::Eq . It's represented
110+
// as a sequence of identifiers, along with a bunch
111+
// of supporting information.
108112
#[auto_encode]
109113
#[auto_decode]
110114
#[deriving_eq]

src/libsyntax/ext/tt/transcribe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct TtFrame {
3636
pub struct TtReader {
3737
sp_diag: span_handler,
3838
interner: @ident_interner,
39+
// the unzipped tree:
3940
cur: @mut TtFrame,
4041
/* for MBE-style macro transcription */
4142
interpolations: std::oldmap::HashMap<ident, @named_match>,

src/libsyntax/parse/common.rs

-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ pub impl Parser {
119119
id: self.get_id() })
120120
}
121121

122-
fn parse_value_ident(&self) -> ast::ident {
123-
return self.parse_ident();
124-
}
125-
126122
// consume token 'tok' if it exists. Returns true if the given
127123
// token was present, false otherwise.
128124
fn eat(&self, tok: &token::Token) -> bool {

src/libsyntax/parse/parser.rs

+16-36
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub impl Parser {
457457
let pur = p.parse_fn_purity();
458458
// NB: at the moment, trait methods are public by default; this
459459
// could change.
460-
let ident = p.parse_method_name();
460+
let ident = p.parse_ident();
461461
462462
let generics = p.parse_generics();
463463
@@ -899,16 +899,9 @@ pub impl Parser {
899899
codemap::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }
900900
}
901901

902-
fn parse_path_without_tps(&self) -> @path {
903-
self.parse_path_without_tps_(|p| p.parse_ident(),
904-
|p| p.parse_ident())
905-
}
906-
907-
fn parse_path_without_tps_(
908-
&self,
909-
parse_ident: fn(&Parser) -> ident,
910-
parse_last_ident: fn(&Parser) -> ident
911-
) -> @path {
902+
// parse a path that doesn't have type parameters attached
903+
fn parse_path_without_tps(&self)
904+
-> @ast::path {
912905
maybe_whole!(self, nt_path);
913906
let lo = self.span.lo;
914907
let global = self.eat(&token::MOD_SEP);
@@ -919,10 +912,10 @@ pub impl Parser {
919912
&& self.look_ahead(1u) == token::MOD_SEP;
920913

921914
if is_not_last {
922-
ids.push(parse_ident(self));
915+
ids.push(self.parse_ident());
923916
self.expect(&token::MOD_SEP);
924917
} else {
925-
ids.push(parse_last_ident(self));
918+
ids.push(self.parse_ident());
926919
break;
927920
}
928921
}
@@ -933,12 +926,7 @@ pub impl Parser {
933926
types: ~[] }
934927
}
935928

936-
fn parse_value_path(&self) -> @path {
937-
self.parse_path_without_tps_(|p| p.parse_ident(),
938-
|p| p.parse_value_ident())
939-
}
940-
941-
fn parse_path_with_tps(&self, colons: bool) -> @path {
929+
fn parse_path_with_tps(&self, colons: bool) -> @ast::path {
942930
debug!("parse_path_with_tps(colons=%b)", colons);
943931

944932
maybe_whole!(self, nt_path);
@@ -2134,11 +2122,7 @@ pub impl Parser {
21342122
}
21352123

21362124
let lo1 = self.last_span.lo;
2137-
let fieldname = if self.look_ahead(1u) == token::COLON {
2138-
self.parse_ident()
2139-
} else {
2140-
self.parse_value_ident()
2141-
};
2125+
let fieldname = self.parse_ident();
21422126
let hi1 = self.last_span.lo;
21432127
let fieldpath = ast_util::ident_to_path(mk_sp(lo1, hi1),
21442128
fieldname);
@@ -2302,7 +2286,7 @@ pub impl Parser {
23022286
}
23032287

23042288
if is_plain_ident(&*self.token) && cannot_be_enum_or_struct {
2305-
let name = self.parse_value_path();
2289+
let name = self.parse_path_without_tps();
23062290
let sub;
23072291
if self.eat(&token::AT) {
23082292
sub = Some(self.parse_pat(refutable));
@@ -2375,7 +2359,7 @@ pub impl Parser {
23752359
*self.last_span,
23762360
~"expected identifier, found path");
23772361
}
2378-
let name = self.parse_value_path();
2362+
let name = self.parse_path_without_tps();
23792363
let sub = if self.eat(&token::AT) {
23802364
Some(self.parse_pat(refutable))
23812365
} else { None };
@@ -2473,7 +2457,7 @@ pub impl Parser {
24732457

24742458
// Potential trouble: if we allow macros with paths instead of
24752459
// idents, we'd need to look ahead past the whole path here...
2476-
let pth = self.parse_value_path();
2460+
let pth = self.parse_path_without_tps();
24772461
self.bump();
24782462

24792463
let id = if *self.token == token::LPAREN {
@@ -2982,7 +2966,7 @@ pub impl Parser {
29822966
}
29832967

29842968
fn parse_fn_header(&self) -> (ident, ast::Generics) {
2985-
let id = self.parse_value_ident();
2969+
let id = self.parse_ident();
29862970
let generics = self.parse_generics();
29872971
(id, generics)
29882972
}
@@ -3005,10 +2989,6 @@ pub impl Parser {
30052989
(ident, item_fn(decl, purity, generics, body), Some(inner_attrs))
30062990
}
30072991

3008-
fn parse_method_name(&self) -> ident {
3009-
self.parse_value_ident()
3010-
}
3011-
30122992
fn parse_method(&self) -> @method {
30132993
let attrs = self.parse_outer_attributes();
30142994
let lo = self.span.lo;
@@ -3018,7 +2998,7 @@ pub impl Parser {
30182998

30192999
let visa = self.parse_visibility();
30203000
let pur = self.parse_fn_purity();
3021-
let ident = self.parse_method_name();
3001+
let ident = self.parse_ident();
30223002
let generics = self.parse_generics();
30233003
let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| {
30243004
p.parse_arg()
@@ -3142,7 +3122,7 @@ pub impl Parser {
31423122
}
31433123

31443124
fn parse_item_struct(&self) -> item_info {
3145-
let class_name = self.parse_value_ident();
3125+
let class_name = self.parse_ident();
31463126
self.parse_region_param();
31473127
let generics = self.parse_generics();
31483128
if self.eat(&token::COLON) {
@@ -3370,7 +3350,7 @@ pub impl Parser {
33703350
}
33713351

33723352
fn parse_item_const(&self) -> item_info {
3373-
let id = self.parse_value_ident();
3353+
let id = self.parse_ident();
33743354
self.expect(&token::COLON);
33753355
let ty = self.parse_ty(false);
33763356
self.expect(&token::EQ);
@@ -3768,7 +3748,7 @@ pub impl Parser {
37683748
kind = enum_variant_kind(nested_enum_def);
37693749
needs_comma = false;
37703750
} else {
3771-
ident = self.parse_value_ident();
3751+
ident = self.parse_ident();
37723752
if self.eat(&token::LBRACE) {
37733753
// Parse a struct variant.
37743754
all_nullary = false;

0 commit comments

Comments
 (0)