@@ -71,17 +71,13 @@ tag piece {
71
71
piece_conv ( conv) ;
72
72
}
73
73
74
- fn bad_fmt_call ( ) {
75
- log "malformed #fmt call" ;
76
- fail;
77
- }
78
-
79
74
// TODO: Need to thread parser through here to handle errors correctly
80
75
fn expand_syntax_ext ( vec[ @ast. expr] args,
81
76
option. t[ @ast. expr] body) -> @ast . expr {
82
77
83
78
if ( _vec. len [ @ast. expr ] ( args) == 0 u) {
84
- bad_fmt_call ( ) ;
79
+ log "malformed #fmt call" ;
80
+ fail;
85
81
}
86
82
87
83
auto fmt = expr_to_str ( args. ( 0 ) ) ;
@@ -101,7 +97,7 @@ fn expr_to_str(@ast.expr expr) -> str {
101
97
}
102
98
}
103
99
}
104
- bad_fmt_call ( ) ;
100
+ log "malformed #fmt call" ;
105
101
fail;
106
102
}
107
103
@@ -146,19 +142,29 @@ fn parse_fmt_string(str s) -> vec[piece] {
146
142
ret pieces;
147
143
}
148
144
149
- fn peek_num ( str s, uint i, uint lim) -> option. t[ tup ( int , int ) ] {
145
+ fn peek_num ( str s, uint i, uint lim) -> option. t[ tup ( uint , uint ) ] {
150
146
if ( i >= lim) {
151
- ret none[ tup ( int, int) ] ;
152
- } else {
153
- ret none[ tup ( int, int) ] ;
154
- /*if ('0' <= c && c <= '9') {
155
- log c;
156
- fail;
157
- } else {
158
- ret option.none[tup(int, int)];
147
+ ret none[ tup ( uint, uint) ] ;
148
+ }
149
+
150
+ // FIXME: Presumably s.(i) will return char eventually
151
+ auto c = s. ( i) ;
152
+ if ( !( '0' as u8 <= c && c <= '9' as u8 ) ) {
153
+ ret option. none [ tup ( uint, uint) ] ;
154
+ }
155
+
156
+ auto n = ( c - ( '0' as u8 ) ) as uint ;
157
+ alt ( peek_num ( s, i + 1 u, lim) ) {
158
+ case ( none[ tup ( uint, uint) ] ) {
159
+ ret some[ tup ( uint, uint) ] ( tup ( n, i + 1 u) ) ;
160
+ }
161
+ case ( some[ tup ( uint, uint) ] ( ?next) ) {
162
+ auto m = next. _0 ;
163
+ auto j = next. _1 ;
164
+ ret some[ tup ( uint, uint) ] ( tup ( n * 10 u + m, j) ) ;
159
165
}
160
- */
161
166
}
167
+
162
168
}
163
169
164
170
fn parse_conversion ( str s, uint i, uint lim) -> tup ( piece , uint ) {
@@ -182,10 +188,10 @@ fn parse_parameter(str s, uint i, uint lim) -> tup(option.t[int], uint) {
182
188
183
189
auto num = peek_num ( s, i, lim) ;
184
190
alt ( num) {
185
- case ( none[ tup ( int , int ) ] ) {
191
+ case ( none[ tup ( uint , uint ) ] ) {
186
192
ret tup ( none[ int] , i) ;
187
193
}
188
- case ( some[ tup ( int , int ) ] ( ?t) ) {
194
+ case ( some[ tup ( uint , uint ) ] ( ?t) ) {
189
195
fail;
190
196
}
191
197
}
@@ -342,6 +348,98 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
342
348
}
343
349
}
344
350
351
+ fn log_conv( conv c) {
352
+ alt ( c. param ) {
353
+ case ( some[ int] ( ?p) ) {
354
+ log "param: " + std. _int . to_str ( p, 10 u) ;
355
+ }
356
+ case ( _) {
357
+ log "param: none" ;
358
+ }
359
+ }
360
+ for ( flag f in c. flags) {
361
+ alt ( f) {
362
+ case ( flag_left_justify) {
363
+ log "flag: left justify" ;
364
+ }
365
+ case ( flag_left_zero_pad) {
366
+ log "flag: left zero pad" ;
367
+ }
368
+ case ( flag_left_space_pad) {
369
+ log "flag: left space pad" ;
370
+ }
371
+ case ( flag_plus_if_positive) {
372
+ log "flag: plus if positive" ;
373
+ }
374
+ case ( flag_alternate) {
375
+ log "flag: alternate" ;
376
+ }
377
+ }
378
+ }
379
+ alt ( c. width) {
380
+ case ( count_is( ?i) ) {
381
+ log "width: count is " + std. _int. to_str( i, 10 u) ;
382
+ }
383
+ case ( count_is_param( ?i) ) {
384
+ log "width: count is param " + std. _int. to_str( i, 10 u) ;
385
+ }
386
+ case ( count_is_next_param) {
387
+ log "width: count is next param" ;
388
+ }
389
+ case ( count_implied) {
390
+ log "width: count is implied" ;
391
+ }
392
+ }
393
+ alt ( c. precision) {
394
+ case ( count_is( ?i) ) {
395
+ log "prec: count is " + std. _int. to_str( i, 10 u) ;
396
+ }
397
+ case ( count_is_param( ?i) ) {
398
+ log "prec: count is param " + std. _int. to_str( i, 10 u) ;
399
+ }
400
+ case ( count_is_next_param) {
401
+ log "prec: count is next param" ;
402
+ }
403
+ case ( count_implied) {
404
+ log "prec: count is implied" ;
405
+ }
406
+ }
407
+ alt ( c. ty) {
408
+ case ( ty_bool) {
409
+ log "type: bool" ;
410
+ }
411
+ case ( ty_str) {
412
+ log "type: str" ;
413
+ }
414
+ case ( ty_char) {
415
+ log "type: char" ;
416
+ }
417
+ case ( ty_int( ?s) ) {
418
+ alt ( s) {
419
+ case ( signed) {
420
+ log "type: signed" ;
421
+ }
422
+ case ( unsigned) {
423
+ log "type: unsigned" ;
424
+ }
425
+ }
426
+ }
427
+ case ( ty_bits) {
428
+ log "type: bits" ;
429
+ }
430
+ case ( ty_hex( ?cs) ) {
431
+ alt ( cs) {
432
+ case ( case_upper) {
433
+ log "type: uhex" ;
434
+ }
435
+ case ( case_lower) {
436
+ log "type: lhex" ;
437
+ }
438
+ }
439
+ }
440
+ }
441
+ }
442
+
345
443
auto sp = args. ( 0 ) . span;
346
444
auto n = 0 u;
347
445
auto tmp_expr = make_new_str( sp, "" ) ;
@@ -358,6 +456,10 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
358
456
fail;
359
457
}
360
458
459
+ // TODO: Remove debug logging
460
+ log "Building conversion:" ;
461
+ log_conv( conv) ;
462
+
361
463
n += 1 u;
362
464
auto arg_expr = args. ( n) ;
363
465
auto c_expr = make_new_conv( conv, arg_expr) ;
@@ -366,10 +468,10 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
366
468
}
367
469
}
368
470
369
- // TODO: Remove this print and return the real expanded AST
471
+ // TODO: Remove this debug logging
370
472
log "dumping expanded ast:" ;
371
473
log pretty. print_expr( tmp_expr) ;
372
- ret make_new_str ( sp , "TODO" ) ;
474
+ ret tmp_expr ;
373
475
}
374
476
375
477
//
0 commit comments