@@ -705,6 +705,7 @@ pub impl Parser {
705
705
@Ty { id : self . get_id ( ) , node : t, span : sp}
706
706
}
707
707
708
+ // parse the type following a @ or a ~
708
709
fn parse_box_or_uniq_pointee (
709
710
& self ,
710
711
sigil : ast:: Sigil ,
@@ -988,12 +989,8 @@ pub impl Parser {
988
989
.. copy * path }
989
990
}
990
991
992
+ /// parses 0 or 1 lifetime
991
993
fn parse_opt_lifetime ( & self ) -> Option < @ast:: Lifetime > {
992
- /*!
993
- *
994
- * Parses 0 or 1 lifetime.
995
- */
996
-
997
994
match * self . token {
998
995
token:: LIFETIME ( * ) => {
999
996
Some ( @self . parse_lifetime ( ) )
@@ -1022,12 +1019,9 @@ pub impl Parser {
1022
1019
}
1023
1020
}
1024
1021
1022
+ /// Parses a single lifetime
1023
+ // matches lifetime = ( LIFETIME ) | ( IDENT / )
1025
1024
fn parse_lifetime ( & self ) -> ast:: Lifetime {
1026
- /*!
1027
- *
1028
- * Parses a single lifetime.
1029
- */
1030
-
1031
1025
match * self . token {
1032
1026
token:: LIFETIME ( i) => {
1033
1027
let span = copy self . span ;
@@ -1147,6 +1141,9 @@ pub impl Parser {
1147
1141
}
1148
1142
}
1149
1143
1144
+ // at the bottom (top?) of the precedence hierarchy,
1145
+ // parse things like parenthesized exprs,
1146
+ // macros, return, etc.
1150
1147
fn parse_bottom_expr( & self ) -> @expr {
1151
1148
maybe_whole_expr!( self ) ;
1152
1149
@@ -1350,6 +1347,7 @@ pub impl Parser {
1350
1347
return self . mk_expr ( blk. span . lo , blk. span . hi , expr_block ( blk) ) ;
1351
1348
}
1352
1349
1350
+ // parse a.b or a(13) or just a
1353
1351
fn parse_dot_or_call_expr ( & self ) -> @expr {
1354
1352
let b = self . parse_bottom_expr ( ) ;
1355
1353
self . parse_dot_or_call_expr_with ( b)
@@ -1618,7 +1616,7 @@ pub impl Parser {
1618
1616
return spanned ( lo, self . span . hi , m) ;
1619
1617
}
1620
1618
1621
-
1619
+ // parse a prefix-operator expr
1622
1620
fn parse_prefix_expr ( & self ) -> @expr {
1623
1621
let lo = self . span . lo ;
1624
1622
let mut hi;
@@ -2552,11 +2550,14 @@ pub impl Parser {
2552
2550
}
2553
2551
2554
2552
fn parse_block ( & self ) -> blk {
2553
+ // disallow inner attrs:
2555
2554
let ( attrs, blk) = self . parse_inner_attrs_and_block ( false ) ;
2556
2555
assert ! ( vec:: is_empty( attrs) ) ;
2557
2556
return blk;
2558
2557
}
2559
2558
2559
+ // I claim the existence of the 'parse_attrs' flag strongly
2560
+ // suggests a name-change or refactoring for this function.
2560
2561
fn parse_inner_attrs_and_block( & self , parse_attrs : bool )
2561
2562
-> ( ~[ attribute ] , blk ) {
2562
2563
@@ -2597,6 +2598,7 @@ pub impl Parser {
2597
2598
self . parse_block_tail_ ( lo, s, ~[ ] )
2598
2599
}
2599
2600
2601
+ // parse the rest of a block expression or function body
2600
2602
fn parse_block_tail_ ( & self , lo : BytePos , s : blk_check_mode ,
2601
2603
+first_item_attrs : ~[ attribute ] ) -> blk {
2602
2604
let mut stmts = ~[ ] ;
@@ -2802,6 +2804,10 @@ pub impl Parser {
2802
2804
ast:: TyParam { ident : ident, id : self . get_id ( ) , bounds : bounds }
2803
2805
}
2804
2806
2807
+ // parse a set of optional generic type parameter declarations
2808
+ // matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > )
2809
+ // | ( < lifetimes , typaramseq ( , )? > )
2810
+ // where typaramseq = ( typaram ) | ( typaram , typaramseq )
2805
2811
fn parse_generics ( & self ) -> ast:: Generics {
2806
2812
if self . eat ( & token:: LT ) {
2807
2813
let lifetimes = self . parse_lifetimes ( ) ;
@@ -2814,6 +2820,7 @@ pub impl Parser {
2814
2820
}
2815
2821
}
2816
2822
2823
+ // parse a generic use site
2817
2824
fn parse_generic_values (
2818
2825
& self ) -> ( OptVec < ast:: Lifetime > , ~[ @Ty ] )
2819
2826
{
@@ -3104,6 +3111,7 @@ pub impl Parser {
3104
3111
}
3105
3112
}
3106
3113
3114
+ // parse trait Foo { ... }
3107
3115
fn parse_item_trait ( & self ) -> item_info {
3108
3116
let ident = self . parse_ident ( ) ;
3109
3117
self . parse_region_param ( ) ;
@@ -3182,13 +3190,15 @@ pub impl Parser {
3182
3190
( ident, item_impl ( generics, opt_trait, ty, meths) , None )
3183
3191
}
3184
3192
3193
+ // parse a::B<~str,int>
3185
3194
fn parse_trait_ref ( & self ) -> @trait_ref {
3186
3195
@ast:: trait_ref {
3187
3196
path : self . parse_path_with_tps ( false ) ,
3188
3197
ref_id : self . get_id ( ) ,
3189
3198
}
3190
3199
}
3191
3200
3201
+ // parse B + C<~str,int> + D
3192
3202
fn parse_trait_ref_list ( & self , ket : & token:: Token ) -> ~[ @trait_ref ] {
3193
3203
self . parse_seq_to_before_end (
3194
3204
ket,
@@ -3197,6 +3207,7 @@ pub impl Parser {
3197
3207
)
3198
3208
}
3199
3209
3210
+ // parse struct Foo { ... }
3200
3211
fn parse_item_struct ( & self ) -> item_info {
3201
3212
let class_name = self . parse_ident ( ) ;
3202
3213
self . parse_region_param ( ) ;
@@ -3446,6 +3457,7 @@ pub impl Parser {
3446
3457
( id, item_const ( ty, e) , None )
3447
3458
}
3448
3459
3460
+ // parse a mod { ...} item
3449
3461
fn parse_item_mod ( & self , outer_attrs : ~[ ast:: attribute ] ) -> item_info {
3450
3462
let id_span = * self . span ;
3451
3463
let id = self . parse_ident ( ) ;
@@ -3702,7 +3714,7 @@ pub impl Parser {
3702
3714
}
3703
3715
} ;
3704
3716
3705
- // extern mod { ... }
3717
+ // extern mod foo { ... } or extern { ... }
3706
3718
if items_allowed && self . eat ( & token:: LBRACE ) {
3707
3719
let abis = opt_abis. get_or_default ( AbiSet :: C ( ) ) ;
3708
3720
@@ -3737,6 +3749,7 @@ pub impl Parser {
3737
3749
( lo, id)
3738
3750
}
3739
3751
3752
+ // parse type Foo = Bar;
3740
3753
fn parse_item_type ( & self ) -> item_info {
3741
3754
let ( _, ident) = self . parse_type_decl ( ) ;
3742
3755
self . parse_region_param ( ) ;
@@ -3747,6 +3760,7 @@ pub impl Parser {
3747
3760
( ident, item_ty ( ty, tps) , None )
3748
3761
}
3749
3762
3763
+ // parse obsolete region parameter
3750
3764
fn parse_region_param( & self ) {
3751
3765
if self . eat ( & token:: BINOP ( token:: SLASH ) ) {
3752
3766
self . obsolete ( * self . last_span , ObsoleteLifetimeNotation ) ;
@@ -3864,6 +3878,7 @@ pub impl Parser {
3864
3878
let generics = self . parse_generics ( ) ;
3865
3879
// Newtype syntax
3866
3880
if * self . token == token:: EQ {
3881
+ // enum x = ty;
3867
3882
self . bump ( ) ;
3868
3883
let ty = self . parse_ty ( false ) ;
3869
3884
self . expect ( & token:: SEMI ) ;
@@ -3888,6 +3903,7 @@ pub impl Parser {
3888
3903
None
3889
3904
) ;
3890
3905
}
3906
+ // enum X { ... }
3891
3907
self . expect ( & token:: LBRACE ) ;
3892
3908
3893
3909
let enum_definition = self . parse_enum_def ( & generics) ;
@@ -3991,7 +4007,7 @@ pub impl Parser {
3991
4007
( self . is_keyword ( & ~"const ") ||
3992
4008
( self . is_keyword ( & ~"static ") &&
3993
4009
!self . token_is_keyword ( & ~"fn ", & self . look_ahead ( 1 ) ) ) ) {
3994
- // CONST ITEM
4010
+ // CONST / STATIC ITEM
3995
4011
if self . is_keyword ( & ~"const ") {
3996
4012
self . obsolete ( * self . span , ObsoleteConstItem ) ;
3997
4013
}
@@ -4007,10 +4023,9 @@ pub impl Parser {
4007
4023
let item = self . parse_item_foreign_const ( visibility, attrs) ;
4008
4024
return iovi_foreign_item ( item) ;
4009
4025
}
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 ") &&
4013
4027
!self . fn_expr_lookahead ( self . look_ahead ( 1 u) ) {
4028
+ // FUNCTION ITEM
4014
4029
self . bump ( ) ;
4015
4030
let ( ident, item_, extra_attrs) =
4016
4031
self . parse_item_fn ( impure_fn, AbiSet :: Rust ( ) ) ;
@@ -4019,7 +4034,7 @@ pub impl Parser {
4019
4034
maybe_append ( attrs, extra_attrs) ) ) ;
4020
4035
}
4021
4036
if items_allowed && self . eat_keyword ( & ~"pure") {
4022
- // PURE FUNCTION ITEM
4037
+ // PURE FUNCTION ITEM (obsolete)
4023
4038
self . obsolete ( * self . last_span , ObsoletePurity ) ;
4024
4039
self . expect_keyword ( & ~"fn ") ;
4025
4040
let ( ident, item_, extra_attrs) =
@@ -4197,6 +4212,12 @@ pub impl Parser {
4197
4212
return view_item_use ( self . parse_view_paths ( ) ) ;
4198
4213
}
4199
4214
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
4200
4221
fn parse_view_path ( & self ) -> @view_path {
4201
4222
let lo = self . span . lo ;
4202
4223
@@ -4286,6 +4307,7 @@ pub impl Parser {
4286
4307
view_path_simple ( last, path, namespace, self . get_id ( ) ) ) ;
4287
4308
}
4288
4309
4310
+ // matches view_paths = view_path | view_path , view_paths
4289
4311
fn parse_view_paths ( & self ) -> ~[ @view_path ] {
4290
4312
let mut vp = ~[ self . parse_view_path ( ) ] ;
4291
4313
while * self . token == token:: COMMA {
@@ -4335,6 +4357,9 @@ pub impl Parser {
4335
4357
4336
4358
// Parses a sequence of items. Stops when it finds program
4337
4359
// 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
4338
4363
fn parse_items_and_view_items ( & self , +first_item_attrs: ~[ attribute] ,
4339
4364
mode: view_item_parse_mode,
4340
4365
macros_allowed: bool )
0 commit comments