Skip to content

Commit e403a78

Browse files
committed
---
yaml --- r: 34414 b: refs/heads/snap-stage3 c: 0a17ab2 h: refs/heads/master v: v3
1 parent b77a4bc commit e403a78

File tree

2 files changed

+52
-41
lines changed

2 files changed

+52
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 1a2a8975bc92b0ebae90d7d9a0cfffec08ec5cf4
4+
refs/heads/snap-stage3: 0a17ab2a9cb4a9c1ce34da670127e45c70e2b99f
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/extfmt.rs

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ pub mod ct {
129129
CountImplied,
130130
}
131131

132+
struct Parsed<T> {
133+
val: T,
134+
next: uint
135+
}
136+
137+
impl<T> Parsed<T> {
138+
static pure fn new(val: T, next: uint) -> Parsed<T> {
139+
Parsed { val: val, next: next }
140+
}
141+
}
142+
132143
// A formatted conversion from an expression to a string
133144
pub struct Conv
134145
{param: Option<uint>,
@@ -169,7 +180,7 @@ pub mod ct {
169180
} else {
170181
buf = flush_buf(move buf, &mut pieces);
171182
let rs = parse_conversion(s, i, lim, err);
172-
pieces.push(copy rs.piece);
183+
pieces.push(copy rs.val);
173184
i = rs.next;
174185
}
175186
} else { buf += curr; i += size; }
@@ -178,7 +189,7 @@ pub mod ct {
178189
move pieces
179190
}
180191
pub fn peek_num(s: &str, i: uint, lim: uint) ->
181-
Option<{num: uint, next: uint}> {
192+
Option<Parsed<uint>> {
182193
let mut j = i;
183194
let mut accum = 0u;
184195
let mut found = false;
@@ -194,54 +205,54 @@ pub mod ct {
194205
}
195206
}
196207
if found {
197-
Some({num: accum, next: j})
208+
Some(Parsed::new(accum, j))
198209
} else {
199210
None
200211
}
201212
}
202213
pub fn parse_conversion(s: &str, i: uint, lim: uint,
203214
err: ErrorFn) ->
204-
{piece: Piece, next: uint} {
215+
Parsed<Piece> {
205216
let parm = parse_parameter(s, i, lim);
206217
let flags = parse_flags(s, parm.next, lim);
207218
let width = parse_count(s, flags.next, lim);
208219
let prec = parse_precision(s, width.next, lim);
209220
let ty = parse_type(s, prec.next, lim, err);
210-
return {piece:
211-
PieceConv(Conv {param: parm.param,
212-
flags: copy flags.flags,
213-
width: width.count,
214-
precision: prec.count,
215-
ty: ty.ty}),
216-
next: ty.next};
221+
return Parsed::new(
222+
PieceConv(Conv {param: parm.val,
223+
flags: copy flags.val,
224+
width: width.val,
225+
precision: prec.val,
226+
ty: ty.val}),
227+
ty.next);
217228
}
218229
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
219-
{param: Option<uint>, next: uint} {
220-
if i >= lim { return {param: None, next: i}; }
230+
Parsed<Option<uint>> {
231+
if i >= lim { return Parsed::new(None, i); }
221232
let num = peek_num(s, i, lim);
222233
return match num {
223-
None => {param: None, next: i},
234+
None => Parsed::new(None, i),
224235
Some(t) => {
225-
let n = t.num;
236+
let n = t.val;
226237
let j = t.next;
227238
if j < lim && s[j] == '$' as u8 {
228-
{param: Some(n), next: j + 1}
229-
} else { {param: None, next: i} }
239+
Parsed::new(Some(n), j + 1)
240+
} else { Parsed::new(None, i) }
230241
}
231242
};
232243
}
233244
pub fn parse_flags(s: &str, i: uint, lim: uint) ->
234-
{flags: ~[Flag], next: uint} {
245+
Parsed<~[Flag]> {
235246
let noflags: ~[Flag] = ~[];
236-
if i >= lim { return {flags: move noflags, next: i}; }
247+
if i >= lim { return Parsed::new(move noflags, i); }
237248
238249
fn more(f: Flag, s: &str, i: uint, lim: uint) ->
239-
{flags: ~[Flag], next: uint} {
250+
Parsed<~[Flag]> {
240251
let next = parse_flags(s, i + 1u, lim);
241-
let rest = copy next.flags;
252+
let rest = copy next.val;
242253
let j = next.next;
243254
let curr: ~[Flag] = ~[f];
244-
return {flags: vec::append(move curr, rest), next: j};
255+
return Parsed::new(vec::append(move curr, rest), j);
245256
}
246257
// Unfortunate, but because s is borrowed, can't use a closure
247258
// fn more(f: Flag, s: &str) { more_(f, s, i, lim); }
@@ -256,48 +267,48 @@ pub mod ct {
256267
more(FlagSignAlways, s, i, lim)
257268
} else if f == '#' as u8 {
258269
more(FlagAlternate, s, i, lim)
259-
} else { {flags: move noflags, next: i} };
270+
} else { Parsed::new(move noflags, i) };
260271
}
261272
pub fn parse_count(s: &str, i: uint, lim: uint)
262-
-> {count: Count, next: uint} {
273+
-> Parsed<Count> {
263274
return if i >= lim {
264-
{count: CountImplied, next: i}
275+
Parsed::new(CountImplied, i)
265276
} else if s[i] == '*' as u8 {
266277
let param = parse_parameter(s, i + 1, lim);
267278
let j = param.next;
268-
match param.param {
269-
None => {count: CountIsNextParam, next: j},
270-
Some(n) => {count: CountIsParam(n), next: j}
279+
match param.val {
280+
None => Parsed::new(CountIsNextParam, j),
281+
Some(n) => Parsed::new(CountIsParam(n), j)
271282
}
272283
} else {
273284
let num = peek_num(s, i, lim);
274285
match num {
275-
None => {count: CountImplied, next: i},
276-
Some(num) => {
277-
count: CountIs(num.num),
278-
next: num.next
279-
}
286+
None => Parsed::new(CountImplied, i),
287+
Some(num) => Parsed::new(
288+
CountIs(num.val),
289+
num.next
290+
)
280291
}
281292
};
282293
}
283294
pub fn parse_precision(s: &str, i: uint, lim: uint) ->
284-
{count: Count, next: uint} {
295+
Parsed<Count> {
285296
return if i >= lim {
286-
{count: CountImplied, next: i}
297+
Parsed::new(CountImplied, i)
287298
} else if s[i] == '.' as u8 {
288299
let count = parse_count(s, i + 1u, lim);
289300
290301
291302
// If there were no digits specified, i.e. the precision
292303
// was ".", then the precision is 0
293-
match count.count {
294-
CountImplied => {count: CountIs(0), next: count.next},
304+
match count.val {
305+
CountImplied => Parsed::new(CountIs(0), count.next),
295306
_ => count
296307
}
297-
} else { {count: CountImplied, next: i} };
308+
} else { Parsed::new(CountImplied, i) };
298309
}
299310
pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
300-
{ty: Ty, next: uint} {
311+
Parsed<Ty> {
301312
if i >= lim { err(~"missing type in conversion"); }
302313
let tstr = str::slice(s, i, i+1u);
303314
// FIXME (#2249): Do we really want two signed types here?
@@ -326,7 +337,7 @@ pub mod ct {
326337
} else if tstr == ~"?" {
327338
TyPoly
328339
} else { err(~"unknown type in conversion: " + tstr) };
329-
return {ty: t, next: i + 1u};
340+
return Parsed::new(t, i + 1u);
330341
}
331342
}
332343

0 commit comments

Comments
 (0)