@@ -120,22 +120,28 @@ macro_rules! maybe_whole_expr {
120
120
}
121
121
122
122
macro_rules! maybe_whole {
123
- { $p: expr, $constructor: path} => { alt copy $p. token {
124
- INTERPOLATED ( $constructor( x) ) { $p. bump( ) ; return x; }
123
+ { $p: expr, $constructor: ident} => { alt copy $p. token {
124
+ INTERPOLATED ( token:: $constructor( x) ) { $p. bump( ) ; return x; }
125
+ _ { }
126
+ } } ;
127
+ { deref $p: expr, $constructor: ident} => { alt copy $p. token {
128
+ INTERPOLATED ( token:: $constructor( x) ) { $p. bump( ) ; return * x; }
129
+ _ { }
130
+ } } ;
131
+ { some $p: expr, $constructor: ident} => { alt copy $p. token {
132
+ INTERPOLATED ( token:: $constructor( x) ) { $p. bump( ) ; return some( x) ; }
133
+ _ { }
134
+ } } ;
135
+ { pair_empty $p: expr, $constructor: ident} => { alt copy $p. token {
136
+ INTERPOLATED ( token:: $constructor( x) ) { $p. bump( ) ; return ( ~[ ] , x) ; }
125
137
_ { }
126
138
} }
139
+
127
140
}
128
141
129
- /* ident is handled by common.rs */
130
142
131
- fn dummy ( ) {
132
- /* we will need this to bootstrap maybe_whole! */
133
- #macro[ [ #maybe_whole_path[ p] ,
134
- alt p. token {
135
- INTERPOLATED ( token:: nt_path ( pt) ) { p. bump ( ) ; return pt; }
136
- _ { } } ] ] ;
137
- }
138
143
144
+ /* ident is handled by common.rs */
139
145
140
146
class parser {
141
147
let sess : parse_sess;
@@ -389,6 +395,8 @@ class parser {
389
395
}
390
396
391
397
fn parse_ty ( colons_before_params : bool ) -> @ty {
398
+ maybe_whole ! { self , nt_ty} ;
399
+
392
400
let lo = self . span . lo ;
393
401
394
402
alt self. maybe_parse_dollar_mac ( ) {
@@ -610,6 +618,7 @@ class parser {
610
618
parse_ident : fn ( parser ) -> ident ,
611
619
parse_last_ident : fn ( parser ) -> ident ) -> @path {
612
620
621
+ maybe_whole ! { self , nt_path} ;
613
622
let lo = self . span . lo ;
614
623
let global = self . eat ( token:: MOD_SEP ) ;
615
624
let mut ids = ~[ ] ;
@@ -638,6 +647,7 @@ class parser {
638
647
fn parse_path_with_tps ( colons : bool ) -> @path {
639
648
debug ! { "parse_path_with_tps(colons=%b)" , colons} ;
640
649
650
+ maybe_whole ! { self , nt_path} ;
641
651
let lo = self . span . lo ;
642
652
let path = self . parse_path_without_tps ( ) ;
643
653
if colons && !self . eat ( token:: MOD_SEP ) {
@@ -1067,6 +1077,8 @@ class parser {
1067
1077
}
1068
1078
1069
1079
fn parse_token_tree ( ) -> token_tree {
1080
+ maybe_whole ! { deref self , nt_tt} ;
1081
+
1070
1082
fn parse_tt_tok ( p : parser , delim_ok : bool ) -> token_tree {
1071
1083
alt p. token {
1072
1084
token:: RPAREN | token:: RBRACE | token:: RBRACKET
@@ -1115,6 +1127,9 @@ class parser {
1115
1127
}
1116
1128
1117
1129
fn parse_matchers() -> ~[matcher] {
1130
+ // unification of matchers and token_trees would vastly improve
1131
+ // the interpolation of matchers
1132
+ maybe_whole!{self, nt_matchers};
1118
1133
let name_idx = @mut 0u;
1119
1134
return self.parse_matcher_subseq(
1120
1135
name_idx, token::LBRACE, token::RBRACE);
@@ -1601,6 +1616,8 @@ class parser {
1601
1616
}
1602
1617
1603
1618
fn parse_pat(refutable: bool) -> @pat {
1619
+ maybe_whole!{self, nt_pat};
1620
+
1604
1621
let lo = self.span.lo;
1605
1622
let mut hi = self.span.hi;
1606
1623
let mut pat;
@@ -1830,6 +1847,8 @@ class parser {
1830
1847
}
1831
1848
1832
1849
fn parse_stmt ( +first_item_attrs : ~[ attribute ] ) -> @stmt {
1850
+ maybe_whole ! { self , nt_stmt} ;
1851
+
1833
1852
fn check_expected_item ( p : parser , current_attrs : ~[ attribute ] ) {
1834
1853
// If we have attributes then we should have an item
1835
1854
if vec:: is_not_empty ( current_attrs) {
@@ -1890,6 +1909,8 @@ class parser {
1890
1909
fn parse_inner_attrs_and_block ( parse_attrs : bool )
1891
1910
-> ( ~[ attribute ] , blk ) {
1892
1911
1912
+ maybe_whole ! { pair_empty self , nt_block} ;
1913
+
1893
1914
fn maybe_parse_inner_attrs_and_next ( p : parser , parse_attrs : bool ) ->
1894
1915
{ inner : ~[ attribute ] , next : ~[ attribute ] } {
1895
1916
if parse_attrs {
@@ -2735,6 +2756,8 @@ class parser {
2735
2756
2736
2757
fn parse_item( +attrs : ~[ attribute ] , vis : visibility )
2737
2758
-> option<@item> {
2759
+
2760
+ maybe_whole ! { some self , nt_item} ;
2738
2761
let lo = self . span . lo ;
2739
2762
let ( ident, item_, extra_attrs) = if self . eat_keyword ( ~"const ") {
2740
2763
self . parse_item_const ( )
0 commit comments