@@ -66,7 +66,7 @@ use codemap::{span, BytePos, spanned, mk_sp};
66
66
use codemap;
67
67
use parse:: attr:: parser_attr;
68
68
use parse:: classify;
69
- use parse:: common:: { seq_sep_none, token_to_str } ;
69
+ use parse:: common:: { seq_sep_none} ;
70
70
use parse:: common:: { seq_sep_trailing_disallowed, seq_sep_trailing_allowed} ;
71
71
use parse:: lexer:: reader;
72
72
use parse:: lexer:: TokenAndSpan ;
@@ -252,8 +252,11 @@ pub fn Parser(sess: @mut ParseSess,
252
252
pub struct Parser {
253
253
sess : @mut ParseSess ,
254
254
cfg : crate_cfg ,
255
+ // the current token:
255
256
token : @mut token:: Token ,
257
+ // the span of the current token:
256
258
span : @mut span ,
259
+ // the span of the prior token:
257
260
last_span : @mut span ,
258
261
buffer : @mut [ TokenAndSpan , ..4 ] ,
259
262
buffer_start : @mut int ,
@@ -499,7 +502,7 @@ pub impl Parser {
499
502
let hi = p. last_span . hi ;
500
503
debug ! ( "parse_trait_methods(): trait method signature ends in \
501
504
`%s`",
502
- token_to_str ( p . reader , & copy * p . token ) ) ;
505
+ self . this_token_to_str ( ) ) ;
503
506
match * p. token {
504
507
token:: SEMI => {
505
508
p. bump ( ) ;
@@ -541,7 +544,7 @@ pub impl Parser {
541
544
p. fatal (
542
545
fmt ! (
543
546
"expected `;` or `}` but found `%s`" ,
544
- token_to_str ( p . reader , & copy * p . token )
547
+ self . this_token_to_str ( )
545
548
)
546
549
) ;
547
550
}
@@ -1456,6 +1459,11 @@ pub impl Parser {
1456
1459
fn parse_token_tree ( & self ) -> token_tree {
1457
1460
maybe_whole ! ( deref self , nt_tt) ;
1458
1461
1462
+ // this is the fall-through for the 'match' below.
1463
+ // invariants: the current token is not a left-delimiter,
1464
+ // not an EOF, and not the desired right-delimiter (if
1465
+ // it were, parse_seq_to_before_end would have prevented
1466
+ // reaching this point.
1459
1467
fn parse_non_delim_tt_tok ( p : & Parser ) -> token_tree {
1460
1468
maybe_whole ! ( deref p, nt_tt) ;
1461
1469
match * p. token {
@@ -1464,7 +1472,7 @@ pub impl Parser {
1464
1472
p. fatal (
1465
1473
fmt ! (
1466
1474
"incorrect close delimiter: `%s`" ,
1467
- token_to_str ( p . reader , & copy * p . token )
1475
+ p . this_token_to_str ( )
1468
1476
)
1469
1477
) ;
1470
1478
}
@@ -1506,18 +1514,17 @@ pub impl Parser {
1506
1514
1507
1515
match * self . token {
1508
1516
token:: EOF => {
1509
- self . fatal ( ~"file ended in the middle of a macro invocation ") ;
1517
+ self . fatal ( ~"file ended with unbalanced delimiters ") ;
1510
1518
}
1511
1519
token:: LPAREN | token:: LBRACE | token:: LBRACKET => {
1512
- // tjc: ??????
1513
- let ket = token:: flip_delimiter ( & * self . token ) ;
1520
+ let close_delim = token:: flip_delimiter ( & * self . token ) ;
1514
1521
tt_delim (
1515
1522
vec:: append (
1516
1523
// the open delimiter:
1517
1524
~[ parse_any_tt_tok ( self ) ] ,
1518
1525
vec:: append (
1519
1526
self . parse_seq_to_before_end (
1520
- & ket ,
1527
+ & close_delim ,
1521
1528
seq_sep_none ( ) ,
1522
1529
|p| p. parse_token_tree ( )
1523
1530
) ,
@@ -1531,6 +1538,8 @@ pub impl Parser {
1531
1538
}
1532
1539
}
1533
1540
1541
+ // parse a stream of tokens into a list of token_trees,
1542
+ // up to EOF.
1534
1543
fn parse_all_token_trees ( & self ) -> ~[ token_tree ] {
1535
1544
let mut tts = ~[ ] ;
1536
1545
while * self . token != token:: EOF {
@@ -2053,6 +2062,7 @@ pub impl Parser {
2053
2062
return e;
2054
2063
}
2055
2064
2065
+ // parse the RHS of a local variable declaration (e.g. '= 14;')
2056
2066
fn parse_initializer ( & self ) -> Option <@expr> {
2057
2067
match * self . token {
2058
2068
token:: EQ => {
@@ -2139,7 +2149,7 @@ pub impl Parser {
2139
2149
self . fatal (
2140
2150
fmt ! (
2141
2151
"expected `}`, found `%s`" ,
2142
- token_to_str ( self . reader , & copy * self . token )
2152
+ self . this_token_to_str ( )
2143
2153
)
2144
2154
) ;
2145
2155
}
@@ -2407,6 +2417,7 @@ pub impl Parser {
2407
2417
pat_ident ( binding_mode, name, sub)
2408
2418
}
2409
2419
2420
+ // parse a local variable declaration
2410
2421
fn parse_local( & self , is_mutbl: bool ,
2411
2422
allow_init: bool ) -> @local {
2412
2423
let lo = self . span . lo ;
@@ -2652,7 +2663,7 @@ pub impl Parser {
2652
2663
fmt ! (
2653
2664
"expected `;` or `}` after \
2654
2665
expression but found `%s`",
2655
- token_to_str ( self . reader , & t)
2666
+ self . token_to_str ( & t)
2656
2667
)
2657
2668
) ;
2658
2669
}
@@ -2867,7 +2878,7 @@ pub impl Parser {
2867
2878
self . fatal (
2868
2879
fmt ! (
2869
2880
"expected `self` but found `%s`" ,
2870
- token_to_str ( self . reader , & copy * self . token )
2881
+ self . this_token_to_str ( )
2871
2882
)
2872
2883
) ;
2873
2884
}
@@ -2991,7 +3002,7 @@ pub impl Parser {
2991
3002
self . fatal (
2992
3003
fmt ! (
2993
3004
"expected `,` or `)`, found `%s`" ,
2994
- token_to_str ( self . reader , & copy * self . token )
3005
+ self . this_token_to_str ( )
2995
3006
)
2996
3007
) ;
2997
3008
}
@@ -3271,7 +3282,7 @@ pub impl Parser {
3271
3282
fmt ! (
3272
3283
"expected `{`, `(`, or `;` after struct name \
3273
3284
but found `%s`",
3274
- token_to_str ( self . reader , & copy * self . token )
3285
+ self . this_token_to_str ( )
3275
3286
)
3276
3287
) ;
3277
3288
}
@@ -3321,7 +3332,7 @@ pub impl Parser {
3321
3332
copy * self . span ,
3322
3333
fmt ! (
3323
3334
"expected `;`, `,`, or '}' but found `%s`" ,
3324
- token_to_str ( self . reader , & copy * self . token )
3335
+ self . this_token_to_str ( )
3325
3336
)
3326
3337
) ;
3327
3338
}
@@ -3423,7 +3434,7 @@ pub impl Parser {
3423
3434
self . fatal (
3424
3435
fmt ! (
3425
3436
"expected item but found `%s`" ,
3426
- token_to_str ( self . reader , & copy * self . token )
3437
+ self . this_token_to_str ( )
3427
3438
)
3428
3439
) ;
3429
3440
}
@@ -3683,7 +3694,7 @@ pub impl Parser {
3683
3694
copy * self . span ,
3684
3695
fmt ! (
3685
3696
"expected `{` or `mod` but found `%s`" ,
3686
- token_to_str ( self . reader , & copy * self . token )
3697
+ self . this_token_to_str ( )
3687
3698
)
3688
3699
) ;
3689
3700
}
@@ -3696,7 +3707,7 @@ pub impl Parser {
3696
3707
copy * self . span ,
3697
3708
fmt ! (
3698
3709
"expected foreign module name but found `%s`" ,
3699
- token_to_str ( self . reader , & copy * self . token )
3710
+ self . this_token_to_str ( )
3700
3711
)
3701
3712
) ;
3702
3713
}
0 commit comments