Skip to content

Commit 0c396b6

Browse files
committed
libsyntax comments only
1 parent 278573f commit 0c396b6

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

src/libsyntax/codemap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,12 @@ pub struct FileLines
206206
lines: ~[uint]
207207
}
208208

209+
// represents the origin of a file:
209210
pub enum FileSubstr {
211+
// indicates that this is a normal standalone file:
210212
pub FssNone,
213+
// indicates that this "file" is actually a substring
214+
// of another file that appears earlier in the codemap
211215
pub FssInternal(span),
212216
}
213217

src/libsyntax/parse/parser.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ pub impl Parser {
705705
@Ty {id: self.get_id(), node: t, span: sp}
706706
}
707707

708+
// parse the type following a @ or a ~
708709
fn parse_box_or_uniq_pointee(
709710
&self,
710711
sigil: ast::Sigil,
@@ -988,12 +989,8 @@ pub impl Parser {
988989
.. copy *path }
989990
}
990991

992+
/// parses 0 or 1 lifetime
991993
fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> {
992-
/*!
993-
*
994-
* Parses 0 or 1 lifetime.
995-
*/
996-
997994
match *self.token {
998995
token::LIFETIME(*) => {
999996
Some(@self.parse_lifetime())
@@ -1022,12 +1019,9 @@ pub impl Parser {
10221019
}
10231020
}
10241021

1022+
/// Parses a single lifetime
1023+
// matches lifetime = ( LIFETIME ) | ( IDENT / )
10251024
fn parse_lifetime(&self) -> ast::Lifetime {
1026-
/*!
1027-
*
1028-
* Parses a single lifetime.
1029-
*/
1030-
10311025
match *self.token {
10321026
token::LIFETIME(i) => {
10331027
let span = copy self.span;
@@ -1147,6 +1141,9 @@ pub impl Parser {
11471141
}
11481142
}
11491143

1144+
// at the bottom (top?) of the precedence hierarchy,
1145+
// parse things like parenthesized exprs,
1146+
// macros, return, etc.
11501147
fn parse_bottom_expr(&self) -> @expr {
11511148
maybe_whole_expr!(self);
11521149

@@ -1350,6 +1347,7 @@ pub impl Parser {
13501347
return self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk));
13511348
}
13521349

1350+
// parse a.b or a(13) or just a
13531351
fn parse_dot_or_call_expr(&self) -> @expr {
13541352
let b = self.parse_bottom_expr();
13551353
self.parse_dot_or_call_expr_with(b)
@@ -1618,7 +1616,7 @@ pub impl Parser {
16181616
return spanned(lo, self.span.hi, m);
16191617
}
16201618

1621-
1619+
// parse a prefix-operator expr
16221620
fn parse_prefix_expr(&self) -> @expr {
16231621
let lo = self.span.lo;
16241622
let mut hi;
@@ -2552,11 +2550,14 @@ pub impl Parser {
25522550
}
25532551

25542552
fn parse_block(&self) -> blk {
2553+
// disallow inner attrs:
25552554
let (attrs, blk) = self.parse_inner_attrs_and_block(false);
25562555
assert!(vec::is_empty(attrs));
25572556
return blk;
25582557
}
25592558

2559+
// I claim the existence of the 'parse_attrs' flag strongly
2560+
// suggests a name-change or refactoring for this function.
25602561
fn parse_inner_attrs_and_block(&self, parse_attrs: bool)
25612562
-> (~[attribute], blk) {
25622563

@@ -2597,6 +2598,7 @@ pub impl Parser {
25972598
self.parse_block_tail_(lo, s, ~[])
25982599
}
25992600

2601+
// parse the rest of a block expression or function body
26002602
fn parse_block_tail_(&self, lo: BytePos, s: blk_check_mode,
26012603
+first_item_attrs: ~[attribute]) -> blk {
26022604
let mut stmts = ~[];
@@ -2802,6 +2804,10 @@ pub impl Parser {
28022804
ast::TyParam { ident: ident, id: self.get_id(), bounds: bounds }
28032805
}
28042806

2807+
// parse a set of optional generic type parameter declarations
2808+
// matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > )
2809+
// | ( < lifetimes , typaramseq ( , )? > )
2810+
// where typaramseq = ( typaram ) | ( typaram , typaramseq )
28052811
fn parse_generics(&self) -> ast::Generics {
28062812
if self.eat(&token::LT) {
28072813
let lifetimes = self.parse_lifetimes();
@@ -2814,6 +2820,7 @@ pub impl Parser {
28142820
}
28152821
}
28162822

2823+
// parse a generic use site
28172824
fn parse_generic_values(
28182825
&self) -> (OptVec<ast::Lifetime>, ~[@Ty])
28192826
{
@@ -3104,6 +3111,7 @@ pub impl Parser {
31043111
}
31053112
}
31063113

3114+
// parse trait Foo { ... }
31073115
fn parse_item_trait(&self) -> item_info {
31083116
let ident = self.parse_ident();
31093117
self.parse_region_param();
@@ -3182,13 +3190,15 @@ pub impl Parser {
31823190
(ident, item_impl(generics, opt_trait, ty, meths), None)
31833191
}
31843192

3193+
// parse a::B<~str,int>
31853194
fn parse_trait_ref(&self) -> @trait_ref {
31863195
@ast::trait_ref {
31873196
path: self.parse_path_with_tps(false),
31883197
ref_id: self.get_id(),
31893198
}
31903199
}
31913200

3201+
// parse B + C<~str,int> + D
31923202
fn parse_trait_ref_list(&self, ket: &token::Token) -> ~[@trait_ref] {
31933203
self.parse_seq_to_before_end(
31943204
ket,
@@ -3197,6 +3207,7 @@ pub impl Parser {
31973207
)
31983208
}
31993209

3210+
// parse struct Foo { ... }
32003211
fn parse_item_struct(&self) -> item_info {
32013212
let class_name = self.parse_ident();
32023213
self.parse_region_param();
@@ -3446,6 +3457,7 @@ pub impl Parser {
34463457
(id, item_const(ty, e), None)
34473458
}
34483459

3460+
// parse a mod { ...} item
34493461
fn parse_item_mod(&self, outer_attrs: ~[ast::attribute]) -> item_info {
34503462
let id_span = *self.span;
34513463
let id = self.parse_ident();
@@ -3702,7 +3714,7 @@ pub impl Parser {
37023714
}
37033715
};
37043716

3705-
// extern mod { ... }
3717+
// extern mod foo { ... } or extern { ... }
37063718
if items_allowed && self.eat(&token::LBRACE) {
37073719
let abis = opt_abis.get_or_default(AbiSet::C());
37083720

@@ -3737,6 +3749,7 @@ pub impl Parser {
37373749
(lo, id)
37383750
}
37393751

3752+
// parse type Foo = Bar;
37403753
fn parse_item_type(&self) -> item_info {
37413754
let (_, ident) = self.parse_type_decl();
37423755
self.parse_region_param();
@@ -3747,6 +3760,7 @@ pub impl Parser {
37473760
(ident, item_ty(ty, tps), None)
37483761
}
37493762

3763+
// parse obsolete region parameter
37503764
fn parse_region_param(&self) {
37513765
if self.eat(&token::BINOP(token::SLASH)) {
37523766
self.obsolete(*self.last_span, ObsoleteLifetimeNotation);
@@ -3864,6 +3878,7 @@ pub impl Parser {
38643878
let generics = self.parse_generics();
38653879
// Newtype syntax
38663880
if *self.token == token::EQ {
3881+
// enum x = ty;
38673882
self.bump();
38683883
let ty = self.parse_ty(false);
38693884
self.expect(&token::SEMI);
@@ -3888,6 +3903,7 @@ pub impl Parser {
38883903
None
38893904
);
38903905
}
3906+
// enum X { ... }
38913907
self.expect(&token::LBRACE);
38923908

38933909
let enum_definition = self.parse_enum_def(&generics);
@@ -3991,7 +4007,7 @@ pub impl Parser {
39914007
(self.is_keyword(&~"const") ||
39924008
(self.is_keyword(&~"static") &&
39934009
!self.token_is_keyword(&~"fn", &self.look_ahead(1)))) {
3994-
// CONST ITEM
4010+
// CONST / STATIC ITEM
39954011
if self.is_keyword(&~"const") {
39964012
self.obsolete(*self.span, ObsoleteConstItem);
39974013
}
@@ -4007,10 +4023,9 @@ pub impl Parser {
40074023
let item = self.parse_item_foreign_const(visibility, attrs);
40084024
return iovi_foreign_item(item);
40094025
}
4010-
if items_allowed &&
4011-
// FUNCTION ITEM (not sure about lookahead condition...)
4012-
self.is_keyword(&~"fn") &&
4026+
if items_allowed && self.is_keyword(&~"fn") &&
40134027
!self.fn_expr_lookahead(self.look_ahead(1u)) {
4028+
// FUNCTION ITEM
40144029
self.bump();
40154030
let (ident, item_, extra_attrs) =
40164031
self.parse_item_fn(impure_fn, AbiSet::Rust());
@@ -4019,7 +4034,7 @@ pub impl Parser {
40194034
maybe_append(attrs, extra_attrs)));
40204035
}
40214036
if items_allowed && self.eat_keyword(&~"pure") {
4022-
// PURE FUNCTION ITEM
4037+
// PURE FUNCTION ITEM (obsolete)
40234038
self.obsolete(*self.last_span, ObsoletePurity);
40244039
self.expect_keyword(&~"fn");
40254040
let (ident, item_, extra_attrs) =
@@ -4197,6 +4212,12 @@ pub impl Parser {
41974212
return view_item_use(self.parse_view_paths());
41984213
}
41994214

4215+
4216+
// matches view_path : MOD? IDENT EQ non_global_path
4217+
// | MOD? non_global_path MOD_SEP LBRACE RBRACE
4218+
// | MOD? non_global_path MOD_SEP LBRACE ident_seq RBRACE
4219+
// | MOD? non_global_path MOD_SEP STAR
4220+
// | MOD? non_global_path
42004221
fn parse_view_path(&self) -> @view_path {
42014222
let lo = self.span.lo;
42024223

@@ -4286,6 +4307,7 @@ pub impl Parser {
42864307
view_path_simple(last, path, namespace, self.get_id()));
42874308
}
42884309

4310+
// matches view_paths = view_path | view_path , view_paths
42894311
fn parse_view_paths(&self) -> ~[@view_path] {
42904312
let mut vp = ~[self.parse_view_path()];
42914313
while *self.token == token::COMMA {
@@ -4335,6 +4357,9 @@ pub impl Parser {
43354357

43364358
// Parses a sequence of items. Stops when it finds program
43374359
// text that can't be parsed as an item
4360+
// - mod_items uses VIEW_ITEMS_AND_ITEMS_ALLOWED
4361+
// - block_tail_ uses IMPORTS_AND_ITEMS_ALLOWED
4362+
// - foreign_mod_items uses FOREIGN_ITEMS_ALLOWED
43384363
fn parse_items_and_view_items(&self, +first_item_attrs: ~[attribute],
43394364
mode: view_item_parse_mode,
43404365
macros_allowed: bool)

0 commit comments

Comments
 (0)