@@ -53,10 +53,11 @@ import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
53
53
ty_infer, ty_mac, ty_method, ty_nil, ty_param, ty_param_bound,
54
54
ty_path, ty_ptr, ty_rec, ty_rptr, ty_tup, ty_u32, ty_uniq,
55
55
ty_vec, ty_fixed_length, tuple_variant_kind, unchecked_blk, uniq,
56
- unsafe_blk, unsafe_fn, variant, view_item, view_item_,
57
- view_item_export, view_item_import, view_item_use, view_path,
58
- view_path_glob, view_path_list, view_path_simple, visibility,
59
- vstore, vstore_box, vstore_fixed, vstore_slice, vstore_uniq} ;
56
+ unnamed_field, unsafe_blk, unsafe_fn, variant, view_item,
57
+ view_item_, view_item_export, view_item_import, view_item_use,
58
+ view_path, view_path_glob, view_path_list, view_path_simple,
59
+ visibility, vstore, vstore_box, vstore_fixed, vstore_slice,
60
+ vstore_uniq} ;
60
61
61
62
export file_type;
62
63
export parser;
@@ -2563,61 +2564,88 @@ class parser {
2563
2564
let traits : ~[ @trait_ref ] = if self . eat ( token:: COLON )
2564
2565
{ self . parse_trait_ref_list ( token:: LBRACE ) }
2565
2566
else { ~[ ] } ;
2566
- self . expect ( token :: LBRACE ) ;
2567
- let mut fields: ~[ @struct_field ] = ~ [ ] ;
2567
+
2568
+ let mut fields: ~[ @struct_field ] ;
2568
2569
let mut methods: ~[ @method ] = ~[ ] ;
2570
+ let mut the_ctor: option < ( fn_decl , ~[ attribute ] , blk , codemap:: span ) >
2571
+ = none;
2572
+ let mut the_dtor: option < ( blk , ~[ attribute ] , codemap:: span ) > = none;
2569
2573
let ctor_id = self . get_id ( ) ;
2570
- let mut the_ctor : option < ( fn_decl , ~[ attribute ] , blk ,
2571
- codemap:: span ) > = none;
2572
- let mut the_dtor : option < ( blk , ~[ attribute ] , codemap:: span ) > = none;
2573
- while self . token != token:: RBRACE {
2574
- match self . parse_class_item ( class_path) {
2575
- ctor_decl( a_fn_decl, attrs, blk, s) => {
2576
- match the_ctor {
2577
- some( ( _, _, _, s_first) ) => {
2578
- self . span_note ( s, #fmt ( "Duplicate constructor \
2579
- declaration for class %s", * class_name) ) ;
2580
- self . span_fatal ( copy s_first, ~"First constructor \
2581
- declared here") ;
2582
- }
2583
- none => {
2584
- the_ctor = some ( ( a_fn_decl, attrs, blk, s) ) ;
2585
- }
2574
+
2575
+ if self . eat ( token:: LBRACE ) {
2576
+ // It's a record-like struct.
2577
+ fields = ~[ ] ;
2578
+ while self . token != token:: RBRACE {
2579
+ match self . parse_class_item ( class_path) {
2580
+ ctor_decl( a_fn_decl, attrs, blk, s) => {
2581
+ match the_ctor {
2582
+ some( ( _, _, _, s_first) ) => {
2583
+ self . span_note ( s, #fmt ( "Duplicate constructor \
2584
+ declaration for class %s", * class_name) ) ;
2585
+ self . span_fatal ( copy s_first, ~"First constructor \
2586
+ declared here") ;
2587
+ }
2588
+ none => {
2589
+ the_ctor = some ( ( a_fn_decl, attrs, blk, s) ) ;
2590
+ }
2591
+ }
2586
2592
}
2587
- }
2588
- dtor_decl ( blk , attrs , s ) => {
2589
- match the_dtor {
2590
- some ( ( _ , _ , s_first ) ) => {
2591
- self . span_note ( s , # fmt ( "Duplicate destructor \
2592
- declaration for class %s" , * class_name ) ) ;
2593
- self . span_fatal ( copy s_first , ~" First destructor \
2594
- declared here" ) ;
2595
- }
2596
- none => {
2597
- the_dtor = some ( ( blk , attrs , s ) ) ;
2598
- }
2593
+ dtor_decl ( blk , attrs , s ) => {
2594
+ match the_dtor {
2595
+ some ( ( _ , _ , s_first ) ) => {
2596
+ self . span_note ( s , # fmt ( "Duplicate destructor \
2597
+ declaration for class %s" , * class_name ) ) ;
2598
+ self . span_fatal ( copy s_first , ~" First destructor \
2599
+ declared here" ) ;
2600
+ }
2601
+ none => {
2602
+ the_dtor = some ( ( blk , attrs , s ) ) ;
2603
+ }
2604
+ }
2599
2605
}
2600
- }
2601
- members ( mms) => {
2602
- for mms . each |mm| {
2603
- match mm {
2604
- @field_member ( struct_field) =>
2605
- vec :: push ( fields , struct_field ) ,
2606
- @method_member ( the_method_member) =>
2607
- vec :: push ( methods , the_method_member )
2606
+ members ( mms ) => {
2607
+ for mms. each |mm| {
2608
+ match mm {
2609
+ @field_member ( struct_field ) =>
2610
+ vec :: push ( fields , struct_field) ,
2611
+ @method_member ( the_method_member ) =>
2612
+ vec :: push ( methods , the_method_member)
2613
+ }
2608
2614
}
2615
+ }
2609
2616
}
2610
- }
2611
2617
}
2618
+ self . bump ( ) ;
2619
+ } else if self . token == token:: LPAREN {
2620
+ // It's a tuple-like struct.
2621
+ fields = do self . parse_unspanned_seq ( token:: LPAREN , token:: RPAREN ,
2622
+ seq_sep_trailing_allowed
2623
+ ( token:: COMMA ) ) |p| {
2624
+ let lo = p. span . lo ;
2625
+ let struct_field_ = {
2626
+ kind: unnamed_field,
2627
+ id: self . get_id ( ) ,
2628
+ ty: p. parse_ty ( false )
2629
+ } ;
2630
+ @spanned ( lo, p. span . hi , struct_field_)
2631
+ } ;
2632
+ self . expect ( token:: SEMI ) ;
2633
+ } else if self . eat ( token:: SEMI ) {
2634
+ // It's a unit-like struct.
2635
+ fields = ~[ ] ;
2636
+ } else {
2637
+ self . fatal ( fmt ! ( "expected `{`, `(`, or `;` after struct name \
2638
+ but found `%s`",
2639
+ token_to_str( self . reader, self . token) ) ) ;
2612
2640
}
2641
+
2613
2642
let actual_dtor = do option:: map ( the_dtor) |dtor| {
2614
2643
let ( d_body, d_attrs, d_s) = dtor;
2615
2644
{ node : { id : self . get_id ( ) ,
2616
2645
attrs : d_attrs,
2617
2646
self_id : self . get_id ( ) ,
2618
2647
body : d_body} ,
2619
2648
span: d_s} } ;
2620
- self . bump ( ) ;
2621
2649
match the_ctor {
2622
2650
some( ( ct_d, ct_attrs, ct_b, ct_s) ) => {
2623
2651
( class_name,
0 commit comments