Skip to content

Commit fa5ba17

Browse files
committed
parser comments
parser comments
1 parent 1b4ced8 commit fa5ba17

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/libsyntax/parse/attr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ impl parser_attr for Parser {
6262
return attrs;
6363
}
6464

65+
// matches attribute = # attribute_naked
6566
fn parse_attribute(&self, style: ast::attr_style) -> ast::attribute {
6667
let lo = self.span.lo;
6768
self.expect(&token::POUND);
6869
return self.parse_attribute_naked(style, lo);
6970
}
7071

72+
// matches attribute_naked = [ meta_item ]
7173
fn parse_attribute_naked(&self, style: ast::attr_style, lo: BytePos) ->
7274
ast::attribute {
7375
self.expect(&token::LBRACKET);
@@ -86,6 +88,7 @@ impl parser_attr for Parser {
8688
// is an inner attribute of the containing item or an outer attribute of
8789
// the first contained item until we see the semi).
8890

91+
// matches inner_attrs* outer_attr?
8992
// you can make the 'next' field an Option, but the result is going to be
9093
// more useful as a vector.
9194
fn parse_inner_attrs_and_next(&self) ->
@@ -134,6 +137,9 @@ impl parser_attr for Parser {
134137
(inner_attrs, next_outer_attrs)
135138
}
136139

140+
// matches meta_item = IDENT
141+
// | IDENT = lit
142+
// | IDENT meta_seq
137143
fn parse_meta_item(&self) -> @ast::meta_item {
138144
let lo = self.span.lo;
139145
let name = self.id_to_str(self.parse_ident());
@@ -156,6 +162,7 @@ impl parser_attr for Parser {
156162
}
157163
}
158164

165+
// matches meta_seq = ( COMMASEP(meta_item) )
159166
fn parse_meta_seq(&self) -> ~[@ast::meta_item] {
160167
copy self.parse_seq(
161168
&token::LPAREN,

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ pub impl Parser {
870870
}
871871
}
872872

873+
// matches token_lit = LIT_INT | ...
873874
fn lit_from_token(&self, tok: &token::Token) -> lit_ {
874875
match *tok {
875876
token::LIT_INT(i, it) => lit_int(i, it),
@@ -884,6 +885,7 @@ pub impl Parser {
884885
}
885886
}
886887

888+
// matches lit = true | false | token_lit
887889
fn parse_lit(&self) -> lit {
888890
let lo = self.span.lo;
889891
let lit = if self.eat_keyword(&~"true") {
@@ -2762,8 +2764,6 @@ pub impl Parser {
27622764
// matches optbounds = ( ( : ( boundseq )? )? )
27632765
// where boundseq = ( bound + boundseq ) | bound
27642766
// and bound = ( 'static ) | ty
2765-
// you might want to insist on the boundseq having seen the colon, but
2766-
// that's not currently in place.
27672767
fn parse_optional_ty_param_bounds(&self) -> @OptVec<TyParamBound> {
27682768
if !self.eat(&token::COLON) {
27692769
return @opt_vec::Empty;
@@ -3085,6 +3085,7 @@ pub impl Parser {
30853085
}
30863086
}
30873087

3088+
// matches fn_header = IDENT generics
30883089
// parse the name and optional generic types of a function header.
30893090
fn parse_fn_header(&self) -> (ident, ast::Generics) {
30903091
let id = self.parse_ident();
@@ -3436,7 +3437,7 @@ pub impl Parser {
34363437
let attrs_remaining_len = attrs_remaining.len();
34373438

34383439
// looks like this code depends on the invariant that
3439-
// outer attributes can't occur on view items (or macros
3440+
// outer attributes can't occur on view items (or macro
34403441
// invocations?)
34413442
let mut first = true;
34423443
while *self.token != term {
@@ -3449,9 +3450,9 @@ pub impl Parser {
34493450
attrs);
34503451
match self.parse_item_or_view_item(
34513452
/*bad*/ copy attrs,
3452-
true,
3453-
false,
3454-
true
3453+
true, // items allowed
3454+
false, // foreign items allowed
3455+
true // macros allowed
34553456
) {
34563457
iovi_item(item) => items.push(item),
34573458
iovi_view_item(view_item) => {
@@ -3706,6 +3707,7 @@ pub impl Parser {
37063707
}
37073708
}
37083709

3710+
// parse extern mod foo { ... } or extern { ... }
37093711
fn parse_item_foreign_mod(&self,
37103712
lo: BytePos,
37113713
opt_abis: Option<AbiSet>,

src/libsyntax/syntax.rc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
/*! This module contains the Rust parser. It maps source text
12+
* to token trees and to ASTs. It contains code for expanding
13+
* macros.
14+
*/
15+
1116
#[link(name = "syntax",
1217
vers = "0.7-pre",
1318
uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")];

0 commit comments

Comments
 (0)