@@ -19,7 +19,9 @@ pub struct StmtIndicesIter<'a> {
19
19
enddelim : u8
20
20
}
21
21
22
- impl < ' a > Iterator < ( uint , uint ) > for StmtIndicesIter < ' a > {
22
+ impl < ' a > Iterator for StmtIndicesIter < ' a > {
23
+ type Item = ( uint , uint ) ;
24
+
23
25
#[ inline]
24
26
fn next ( & mut self ) -> Option < ( uint , uint ) > {
25
27
let semicolon: u8 = ";" . as_bytes ( ) [ 0 ] ;
@@ -78,10 +80,10 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
78
80
self . start = self . pos ;
79
81
}
80
82
81
-
83
+
82
84
// if the statement starts with 'macro_rules!' then we're in a macro
83
85
// We need to know this because a closeparen can terminate a macro
84
- if ( self . end - self . pos ) > 12 &&
86
+ if ( self . end - self . pos ) > 12 &&
85
87
self . src . slice ( self . pos , self . pos +12 ) == "macro_rules!" {
86
88
self . is_macro = true ;
87
89
}
@@ -92,14 +94,14 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
92
94
93
95
// macros can be terminated by closeparen if opened by one
94
96
if self . is_macro &&
95
- self . bracelevel == 0 &&
97
+ self . bracelevel == 0 &&
96
98
self . parenlevel == 0 {
97
99
self . enddelim = closeparen;
98
100
}
99
-
101
+
100
102
// also macro invocations can too
101
103
if self . pos > 0 && src_bytes[ self . pos -1 ] == bang &&
102
- self . bracelevel == 0 &&
104
+ self . bracelevel == 0 &&
103
105
self . parenlevel == 0 {
104
106
self . enddelim = closeparen;
105
107
}
@@ -110,9 +112,9 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
110
112
self . parenlevel -= 1 ;
111
113
112
114
} else if src_bytes[ self . pos ] == openbrace {
113
- // if we are top level and stmt is not a 'use' then
115
+ // if we are top level and stmt is not a 'use' then
114
116
// closebrace finishes the stmt
115
- if self . bracelevel == 0 &&
117
+ if self . bracelevel == 0 &&
116
118
self . parenlevel == 0 &&
117
119
!( is_a_use_stmt ( self . src , self . start , self . pos ) ) {
118
120
self . enddelim = closebrace;
@@ -128,12 +130,12 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
128
130
}
129
131
130
132
// attribute #[foo = bar]
131
- if self . bracelevel == 0 && self . start == self . pos &&
133
+ if self . bracelevel == 0 && self . start == self . pos &&
132
134
src_bytes[ self . pos ] == hash {
133
135
self . enddelim = closesqbrace;
134
136
}
135
137
136
- if self . bracelevel == 0 && self . parenlevel == 0 &&
138
+ if self . bracelevel == 0 && self . parenlevel == 0 &&
137
139
src_bytes[ self . pos ] == self . enddelim {
138
140
let start = self . start ;
139
141
self . start = self . pos +1 ;
@@ -145,24 +147,24 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
145
147
146
148
self . pos += 1 ;
147
149
}
148
-
150
+
149
151
}
150
152
}
151
153
}
152
154
153
155
fn is_a_use_stmt ( src : & str , start : uint , pos : uint ) -> bool {
154
156
let src_bytes = src. as_bytes ( ) ;
155
157
let whitespace = " {\t \r \n " . as_bytes ( ) ;
156
- ( pos > 3 && src_bytes. slice ( start, start+3 ) == "use" . as_bytes ( ) &&
157
- whitespace. contains ( & src_bytes[ start+3 ] ) ) ||
158
+ ( pos > 3 && src_bytes. slice ( start, start+3 ) == "use" . as_bytes ( ) &&
159
+ whitespace. contains ( & src_bytes[ start+3 ] ) ) ||
158
160
( pos > 7 && src_bytes. slice ( start, start+7 ) == "pub use" . as_bytes ( ) &&
159
161
whitespace. contains ( & src_bytes[ start+7 ] ) )
160
162
}
161
163
162
164
pub fn iter_stmts < ' a > ( src : & ' a str ) -> StmtIndicesIter < ' a > {
163
165
let semicolon: u8 = ";" . as_bytes ( ) [ 0 ] ;
164
- StmtIndicesIter { src : src, it : code_chunks ( src) ,
165
- pos : 0 , start : 0 , end : 0 , bracelevel : 0 ,
166
+ StmtIndicesIter { src : src, it : code_chunks ( src) ,
167
+ pos : 0 , start : 0 , end : 0 , bracelevel : 0 ,
166
168
parenlevel : 0 , enddelim : semicolon, is_macro : false }
167
169
}
168
170
0 commit comments