@@ -21,6 +21,7 @@ use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
21
21
use parse:: token:: { Token , EOF , Nonterminal } ;
22
22
use parse:: token;
23
23
24
+ use std:: rc:: Rc ;
24
25
use collections:: HashMap ;
25
26
26
27
/* This is an Earley-like parser, without support for in-grammar nonterminals,
@@ -102,7 +103,7 @@ pub struct MatcherPos {
102
103
sep : Option < Token > ,
103
104
idx : uint ,
104
105
up : Option < ~MatcherPos > ,
105
- matches : Vec < Vec < @ NamedMatch > > ,
106
+ matches : Vec < Vec < Rc < NamedMatch > > > ,
106
107
match_lo : uint , match_hi : uint ,
107
108
sp_lo : BytePos ,
108
109
}
@@ -165,14 +166,14 @@ pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos)
165
166
// ast::Matcher it was derived from.
166
167
167
168
pub enum NamedMatch {
168
- MatchedSeq ( Vec < @ NamedMatch > , codemap:: Span ) ,
169
+ MatchedSeq ( Vec < Rc < NamedMatch > > , codemap:: Span ) ,
169
170
MatchedNonterminal ( Nonterminal )
170
171
}
171
172
172
- pub fn nameize ( p_s : & ParseSess , ms : & [ Matcher ] , res : & [ @ NamedMatch ] )
173
- -> HashMap < Ident , @ NamedMatch > {
174
- fn n_rec ( p_s : & ParseSess , m : & Matcher , res : & [ @ NamedMatch ] ,
175
- ret_val : & mut HashMap < Ident , @ NamedMatch > ) {
173
+ pub fn nameize ( p_s : & ParseSess , ms : & [ Matcher ] , res : & [ Rc < NamedMatch > ] )
174
+ -> HashMap < Ident , Rc < NamedMatch > > {
175
+ fn n_rec ( p_s : & ParseSess , m : & Matcher , res : & [ Rc < NamedMatch > ] ,
176
+ ret_val : & mut HashMap < Ident , Rc < NamedMatch > > ) {
176
177
match * m {
177
178
codemap:: Spanned { node : MatchTok ( _) , .. } => ( ) ,
178
179
codemap:: Spanned { node : MatchSeq ( ref more_ms, _, _, _, _) , .. } => {
@@ -189,7 +190,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch])
189
190
p_s. span_diagnostic
190
191
. span_fatal ( span, "duplicated bind name: " + string. get ( ) )
191
192
}
192
- ret_val. insert ( bind_name, res[ idx] ) ;
193
+ ret_val. insert ( bind_name, res[ idx] . clone ( ) ) ;
193
194
}
194
195
}
195
196
}
@@ -199,7 +200,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch])
199
200
}
200
201
201
202
pub enum ParseResult {
202
- Success ( HashMap < Ident , @ NamedMatch > ) ,
203
+ Success ( HashMap < Ident , Rc < NamedMatch > > ) ,
203
204
Failure ( codemap:: Span , ~str ) ,
204
205
Error ( codemap:: Span , ~str )
205
206
}
@@ -208,7 +209,7 @@ pub fn parse_or_else(sess: &ParseSess,
208
209
cfg : ast:: CrateConfig ,
209
210
rdr : TtReader ,
210
211
ms : Vec < Matcher > )
211
- -> HashMap < Ident , @ NamedMatch > {
212
+ -> HashMap < Ident , Rc < NamedMatch > > {
212
213
match parse ( sess, cfg, rdr, ms. as_slice ( ) ) {
213
214
Success ( m) => m,
214
215
Failure ( sp, str) => sess. span_diagnostic . span_fatal ( sp, str) ,
@@ -282,8 +283,8 @@ pub fn parse(sess: &ParseSess,
282
283
let sub = ( * ei. matches . get ( idx) ) . clone ( ) ;
283
284
new_pos. matches
284
285
. get_mut ( idx)
285
- . push ( @ MatchedSeq ( sub, mk_sp ( ei. sp_lo ,
286
- sp. hi ) ) ) ;
286
+ . push ( Rc :: new ( MatchedSeq ( sub, mk_sp ( ei. sp_lo ,
287
+ sp. hi ) ) ) ) ;
287
288
}
288
289
289
290
new_pos. idx += 1 ;
@@ -325,7 +326,7 @@ pub fn parse(sess: &ParseSess,
325
326
for idx in range ( match_idx_lo, match_idx_hi) {
326
327
new_ei. matches
327
328
. get_mut ( idx)
328
- . push ( @ MatchedSeq ( Vec :: new ( ) , sp) ) ;
329
+ . push ( Rc :: new ( MatchedSeq ( Vec :: new ( ) , sp) ) ) ;
329
330
}
330
331
331
332
cur_eis. push ( new_ei) ;
@@ -401,8 +402,8 @@ pub fn parse(sess: &ParseSess,
401
402
match ei. elts . get ( ei. idx ) . node {
402
403
MatchNonterminal ( _, name, idx) => {
403
404
let name_string = token:: get_ident ( name) ;
404
- ei. matches . get_mut ( idx) . push ( @ MatchedNonterminal (
405
- parse_nt ( & mut rust_parser, name_string. get ( ) ) ) ) ;
405
+ ei. matches . get_mut ( idx) . push ( Rc :: new ( MatchedNonterminal (
406
+ parse_nt ( & mut rust_parser, name_string. get ( ) ) ) ) ) ;
406
407
ei. idx += 1 u;
407
408
}
408
409
_ => fail ! ( )
0 commit comments