@@ -154,6 +154,8 @@ pub struct Parser<'a> {
154
154
style : Option < usize > ,
155
155
/// How many newlines have been seen in the string so far, to adjust the error spans
156
156
seen_newlines : usize ,
157
+ /// Start and end byte offset of every successfuly parsed argument
158
+ pub arg_places : Vec < ( usize , usize ) > ,
157
159
}
158
160
159
161
impl < ' a > Iterator for Parser < ' a > {
@@ -168,9 +170,13 @@ impl<'a> Iterator for Parser<'a> {
168
170
if self . consume ( '{' ) {
169
171
Some ( String ( self . string ( pos + 1 ) ) )
170
172
} else {
171
- let ret = Some ( NextArgument ( self . argument ( ) ) ) ;
172
- self . must_consume ( '}' ) ;
173
- ret
173
+ let mut arg = self . argument ( ) ;
174
+ if let Some ( arg_pos) = self . must_consume ( '}' ) . map ( |end| {
175
+ ( pos + raw + 1 , end + raw + 2 )
176
+ } ) {
177
+ self . arg_places . push ( arg_pos) ;
178
+ }
179
+ Some ( NextArgument ( arg) )
174
180
}
175
181
}
176
182
'}' => {
@@ -211,6 +217,7 @@ impl<'a> Parser<'a> {
211
217
curarg : 0 ,
212
218
style,
213
219
seen_newlines : 0 ,
220
+ arg_places : vec ! [ ] ,
214
221
}
215
222
}
216
223
@@ -271,20 +278,22 @@ impl<'a> Parser<'a> {
271
278
272
279
/// Forces consumption of the specified character. If the character is not
273
280
/// found, an error is emitted.
274
- fn must_consume ( & mut self , c : char ) {
281
+ fn must_consume ( & mut self , c : char ) -> Option < usize > {
275
282
self . ws ( ) ;
276
283
let raw = self . style . unwrap_or ( 0 ) ;
277
284
278
285
let padding = raw + self . seen_newlines ;
279
286
if let Some ( & ( pos, maybe) ) = self . cur . peek ( ) {
280
287
if c == maybe {
281
288
self . cur . next ( ) ;
289
+ Some ( pos)
282
290
} else {
283
291
let pos = pos + padding + 1 ;
284
292
self . err ( format ! ( "expected `{:?}`, found `{:?}`" , c, maybe) ,
285
293
format ! ( "expected `{}`" , c) ,
286
294
pos,
287
295
pos) ;
296
+ None
288
297
}
289
298
} else {
290
299
let msg = format ! ( "expected `{:?}` but string was terminated" , c) ;
@@ -302,6 +311,7 @@ impl<'a> Parser<'a> {
302
311
} else {
303
312
self . err ( msg, format ! ( "expected `{:?}`" , c) , pos, pos) ;
304
313
}
314
+ None
305
315
}
306
316
}
307
317
0 commit comments