@@ -15,6 +15,12 @@ use common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed,
15
15
seq_sep_none, token_to_str} ;
16
16
use dvec:: DVec ;
17
17
use vec:: { push} ;
18
+ use obsolete:: {
19
+ ObsoleteReporter , ObsoleteSyntax ,
20
+ ObsoleteLowerCaseKindBounds , ObsoleteLet ,
21
+ ObsoleteFieldTerminator , ObsoleteStructCtor ,
22
+ ObsoleteWith
23
+ } ;
18
24
use ast:: { _mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
19
25
bind_by_ref, bind_by_implicit_ref, bind_by_value, bind_by_move,
20
26
bitand, bitor, bitxor, blk, blk_check_mode, bound_const,
@@ -208,7 +214,8 @@ fn parser(sess: parse_sess, cfg: ast::crate_cfg,
208
214
restriction: UNRESTRICTED ,
209
215
quote_depth: 0 u,
210
216
keywords: token:: keyword_table( ) ,
211
- restricted_keywords: token:: restricted_keyword_table( )
217
+ restricted_keywords: token:: restricted_keyword_table( ) ,
218
+ obsolete_set: std:: map:: hashmap( ) ,
212
219
}
213
220
}
214
221
@@ -228,6 +235,9 @@ struct parser {
228
235
interner: interner<@~str >,
229
236
keywords: hashmap<~str , ( ) >,
230
237
restricted_keywords: hashmap<~str , ( ) >,
238
+ /// The set of seen errors about obsolete syntax. Used to suppress
239
+ /// extra detail when the same error is seen twice
240
+ obsolete_set: hashmap<ObsoleteSyntax , ( ) >,
231
241
232
242
drop { } /* do not copy the parser; its state is tied to outside state */
233
243
@@ -276,6 +286,12 @@ struct parser {
276
286
fn warn( m: ~str ) {
277
287
self . sess. span_diagnostic. span_warn( copy self . span, m)
278
288
}
289
+ fn span_err( sp: span, m: ~str ) {
290
+ self . sess. span_diagnostic. span_err( sp, m)
291
+ }
292
+ fn abort_if_errors( ) {
293
+ self . sess. span_diagnostic. handler( ) . abort_if_errors( ) ;
294
+ }
279
295
fn get_id( ) -> node_id { next_node_id( self . sess) }
280
296
281
297
pure fn id_to_str( id: ident) -> @~str { self . sess. interner. get( id) }
@@ -1004,24 +1020,28 @@ struct parser {
1004
1020
// It's a struct literal.
1005
1021
self . bump ( ) ;
1006
1022
let mut fields = ~[ ] ;
1023
+ let mut base = None ;
1007
1024
vec:: push ( fields, self . parse_field ( token:: COLON ) ) ;
1008
1025
while self . token != token:: RBRACE {
1026
+
1027
+ if self . try_parse_obsolete_with ( ) {
1028
+ break ;
1029
+ }
1030
+
1009
1031
self . expect ( token:: COMMA ) ;
1010
- if self . token == token:: RBRACE ||
1011
- self . token == token:: DOTDOT {
1032
+
1033
+ if self . eat ( token:: DOTDOT ) {
1034
+ base = Some ( self . parse_expr ( ) ) ;
1035
+ break ;
1036
+ }
1037
+
1038
+ if self . token == token:: RBRACE {
1012
1039
// Accept an optional trailing comma.
1013
1040
break ;
1014
1041
}
1015
1042
vec:: push ( fields, self . parse_field ( token:: COLON ) ) ;
1016
1043
}
1017
1044
1018
- let base;
1019
- if self . eat ( token:: DOTDOT ) {
1020
- base = Some ( self . parse_expr ( ) ) ;
1021
- } else {
1022
- base = None ;
1023
- }
1024
-
1025
1045
hi = pth. span . hi ;
1026
1046
self . expect ( token:: RBRACE ) ;
1027
1047
ex = expr_struct ( pth, fields, base) ;
@@ -1664,6 +1684,10 @@ struct parser {
1664
1684
base = Some ( self . parse_expr ( ) ) ; break ;
1665
1685
}
1666
1686
1687
+ if self . try_parse_obsolete_with ( ) {
1688
+ break ;
1689
+ }
1690
+
1667
1691
self . expect ( token:: COMMA ) ;
1668
1692
if self . token == token:: RBRACE {
1669
1693
// record ends by an optional trailing comma
@@ -2281,12 +2305,22 @@ struct parser {
2281
2305
if is_ident ( self . token ) {
2282
2306
// XXX: temporary until kinds become traits
2283
2307
let maybe_bound = match self . token {
2284
- token:: IDENT ( sid, _) => {
2308
+ token:: IDENT ( copy sid, _) => {
2285
2309
match * self . id_to_str ( sid) {
2286
2310
~"Send " => Some ( bound_send) ,
2287
2311
~"Copy " => Some ( bound_copy) ,
2288
2312
~"Const " => Some ( bound_const) ,
2289
2313
~"Owned " => Some ( bound_owned) ,
2314
+
2315
+ ~"send"
2316
+ | ~"copy"
2317
+ | ~"const "
2318
+ | ~"owned" => {
2319
+ self . obsolete ( copy self . span ,
2320
+ ObsoleteLowerCaseKindBounds ) ;
2321
+ None
2322
+ }
2323
+
2290
2324
_ => None
2291
2325
}
2292
2326
}
@@ -2737,11 +2771,18 @@ struct parser {
2737
2771
}
2738
2772
2739
2773
fn parse_single_class_item ( vis : visibility ) -> @class_member {
2740
- if ( self . token_is_keyword ( ~"mut ", copy self . token ) ||
2741
- !self . is_any_keyword ( copy self . token ) ) &&
2742
- !self . token_is_pound_or_doc_comment ( self . token ) {
2774
+ let obsolete_let = self . eat_obsolete_ident ( "let" ) ;
2775
+ if obsolete_let { self . obsolete ( copy self . last_span , ObsoleteLet ) }
2776
+
2777
+ if ( obsolete_let || self . token_is_keyword ( ~"mut ", copy self . token ) ||
2778
+ !self . is_any_keyword ( copy self . token ) ) &&
2779
+ !self . token_is_pound_or_doc_comment ( self . token ) {
2743
2780
let a_var = self . parse_instance_var ( vis) ;
2744
2781
match self . token {
2782
+ token:: SEMI => {
2783
+ self . obsolete ( copy self . span , ObsoleteFieldTerminator ) ;
2784
+ self . bump ( ) ;
2785
+ }
2745
2786
token:: COMMA => {
2746
2787
self . bump ( ) ;
2747
2788
}
@@ -2792,6 +2833,10 @@ struct parser {
2792
2833
2793
2834
let attrs = self . parse_outer_attributes ( ) ;
2794
2835
2836
+ if self . try_parse_obsolete_struct_ctor ( ) {
2837
+ return members ( ~[ ] ) ;
2838
+ }
2839
+
2795
2840
if self . eat_keyword ( ~"drop") {
2796
2841
return self . parse_dtor ( attrs) ;
2797
2842
}
0 commit comments