@@ -246,6 +246,7 @@ pub fn Parser(sess: @mut ParseSess,
246
246
}
247
247
}
248
248
249
+ // ooh, nasty mutable fields everywhere....
249
250
pub struct Parser {
250
251
sess : @mut ParseSess ,
251
252
cfg : crate_cfg ,
@@ -338,13 +339,15 @@ pub impl Parser {
338
339
self . sess . interner . get ( id)
339
340
}
340
341
342
+ // is this one of the keywords that signals a closure type?
341
343
fn token_is_closure_keyword ( & self , tok : & token:: Token ) -> bool {
342
344
self . token_is_keyword ( & ~"pure", tok) ||
343
345
self . token_is_keyword ( & ~"unsafe ", tok) ||
344
346
self . token_is_keyword ( & ~"once", tok) ||
345
347
self . token_is_keyword ( & ~"fn ", tok)
346
348
}
347
349
350
+ // parse a ty_bare_fun type:
348
351
fn parse_ty_bare_fn ( & self ) -> ty_
349
352
{
350
353
/*
@@ -372,6 +375,7 @@ pub impl Parser {
372
375
} ) ;
373
376
}
374
377
378
+ // parse a ty_closure type
375
379
fn parse_ty_closure ( & self ,
376
380
sigil : ast:: Sigil ,
377
381
region : Option < @ast:: Lifetime > ) -> ty_
@@ -430,6 +434,7 @@ pub impl Parser {
430
434
}
431
435
}
432
436
437
+ // parse a function type (following the 'fn')
433
438
fn parse_ty_fn_decl ( & self ) -> ( fn_decl , OptVec < ast:: Lifetime > ) {
434
439
/*
435
440
@@ -541,12 +546,14 @@ pub impl Parser {
541
546
}
542
547
543
548
549
+ // parse a possibly mutable type
544
550
fn parse_mt ( & self ) -> mt {
545
551
let mutbl = self . parse_mutability ( ) ;
546
552
let t = self . parse_ty ( false ) ;
547
553
mt { ty : t, mutbl : mutbl }
548
554
}
549
555
556
+ // parse [mut/const/imm] ID : TY
550
557
fn parse_ty_field ( & self ) -> ty_field {
551
558
let lo = self . span . lo ;
552
559
let mutbl = self . parse_mutability ( ) ;
@@ -563,6 +570,7 @@ pub impl Parser {
563
570
)
564
571
}
565
572
573
+ // parse optional return type [ -> TY ] in function decl
566
574
fn parse_ret_ty ( & self ) -> ( ret_style , @Ty ) {
567
575
return if self . eat ( & token:: RARROW ) {
568
576
let lo = self . span . lo ;
@@ -591,6 +599,7 @@ pub impl Parser {
591
599
}
592
600
}
593
601
602
+ // parse a type.
594
603
// Useless second parameter for compatibility with quasiquote macros.
595
604
// Bleh!
596
605
fn parse_ty ( & self , _: bool ) -> @Ty {
@@ -627,15 +636,19 @@ pub impl Parser {
627
636
t
628
637
}
629
638
} else if * self . token == token:: AT {
639
+ // MANAGED POINTER
630
640
self . bump ( ) ;
631
641
self . parse_box_or_uniq_pointee ( ManagedSigil , ty_box)
632
642
} else if * self . token == token:: TILDE {
643
+ // OWNED POINTER
633
644
self . bump ( ) ;
634
645
self . parse_box_or_uniq_pointee ( OwnedSigil , ty_uniq)
635
646
} else if * self . token == token:: BINOP ( token:: STAR ) {
647
+ // STAR POINTER (bare pointer?)
636
648
self . bump ( ) ;
637
649
ty_ptr ( self . parse_mt ( ) )
638
650
} else if * self . token == token:: LBRACE {
651
+ // STRUCTURAL RECORD (remove?)
639
652
let elems = self . parse_unspanned_seq (
640
653
& token:: LBRACE ,
641
654
& token:: RBRACE ,
@@ -648,6 +661,7 @@ pub impl Parser {
648
661
self . obsolete ( * self . last_span , ObsoleteRecordType ) ;
649
662
ty_nil
650
663
} else if * self . token == token:: LBRACKET {
664
+ // VECTOR
651
665
self . expect ( & token:: LBRACKET ) ;
652
666
let mt = self . parse_mt ( ) ;
653
667
if mt. mutbl == m_mutbl { // `m_const` too after snapshot
@@ -663,16 +677,20 @@ pub impl Parser {
663
677
self . expect ( & token:: RBRACKET ) ;
664
678
t
665
679
} else if * self . token == token:: BINOP ( token:: AND ) {
680
+ // BORROWED POINTER
666
681
self . bump ( ) ;
667
682
self . parse_borrowed_pointee ( )
668
683
} else if self . eat_keyword ( & ~"extern ") {
684
+ // EXTERN FUNCTION
669
685
self . parse_ty_bare_fn ( )
670
686
} else if self . token_is_closure_keyword ( & copy * self . token ) {
687
+ // CLOSURE
671
688
let result = self . parse_ty_closure ( ast:: BorrowedSigil , None ) ;
672
689
self . obsolete ( * self . last_span , ObsoleteBareFnType ) ;
673
690
result
674
691
} else if * self . token == token:: MOD_SEP
675
692
|| is_ident_or_path ( & * self . token ) {
693
+ // NAMED TYPE
676
694
let path = self . parse_path_with_tps ( false ) ;
677
695
ty_path ( path, self . get_id ( ) )
678
696
} else {
@@ -881,6 +899,8 @@ pub impl Parser {
881
899
let global = self . eat ( & token:: MOD_SEP ) ;
882
900
let mut ids = ~[ ] ;
883
901
loop {
902
+ // if there's a ::< coming, stop processing
903
+ // the path.
884
904
let is_not_last =
885
905
self . look_ahead ( 2 u) != token:: LT
886
906
&& self . look_ahead ( 1 u) == token:: MOD_SEP ;
@@ -900,6 +920,9 @@ pub impl Parser {
900
920
types : ~[ ] }
901
921
}
902
922
923
+ // parse a path optionally with type parameters. If 'colons'
924
+ // is true, then type parameters must be preceded by colons,
925
+ // as in a::t::<t1,t2>
903
926
fn parse_path_with_tps ( & self , colons : bool ) -> @ast:: path {
904
927
debug ! ( "parse_path_with_tps(colons=%b)" , colons) ;
905
928
@@ -1067,6 +1090,7 @@ pub impl Parser {
1067
1090
self.token_is_keyword(&~" const", tok)
1068
1091
}
1069
1092
1093
+ // parse mutability declaration (mut/const/imm)
1070
1094
fn parse_mutability ( & self ) -> mutability {
1071
1095
if self . eat_keyword ( & ~"mut ") {
1072
1096
m_mutbl
0 commit comments