diff options
| author | bors <bors@rust-lang.org> | 2014-03-28 20:21:45 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-28 20:21:45 -0700 |
| commit | 6584f3746e552a626003f564e2f83262d93cbd57 (patch) | |
| tree | b5ee7f3495c68acd4fb712ca4f762b41bff384fb /src/libsyntax/ext/tt/macro_parser.rs | |
| parent | b334f7c3cc3fcab8170ccb46a1f9a12702a2582c (diff) | |
| parent | b0e3cb5f32ec25efb9af65293f9d776b6374b657 (diff) | |
| download | rust-6584f3746e552a626003f564e2f83262d93cbd57.tar.gz rust-6584f3746e552a626003f564e2f83262d93cbd57.zip | |
auto merge of #13170 : eddyb/rust/syntax-cleanup, r=alexcrichton
Removes all Cell's/RefCell's from lexer::Reader implementations and a couple @.
Diffstat (limited to 'src/libsyntax/ext/tt/macro_parser.rs')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 0d90093a40f..ae537cc4782 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -21,6 +21,7 @@ use parse::parser::{LifetimeAndTypesWithoutColons, Parser}; use parse::token::{Token, EOF, Nonterminal}; use parse::token; +use std::rc::Rc; use collections::HashMap; /* This is an Earley-like parser, without support for in-grammar nonterminals, @@ -102,7 +103,7 @@ pub struct MatcherPos { sep: Option<Token>, idx: uint, up: Option<~MatcherPos>, - matches: Vec<Vec<@NamedMatch>>, + matches: Vec<Vec<Rc<NamedMatch>>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, } @@ -165,14 +166,14 @@ pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos) // ast::Matcher it was derived from. pub enum NamedMatch { - MatchedSeq(Vec<@NamedMatch> , codemap::Span), + MatchedSeq(Vec<Rc<NamedMatch>>, codemap::Span), MatchedNonterminal(Nonterminal) } -pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) - -> HashMap<Ident, @NamedMatch> { - fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[@NamedMatch], - ret_val: &mut HashMap<Ident, @NamedMatch>) { +pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[Rc<NamedMatch>]) + -> HashMap<Ident, Rc<NamedMatch>> { + fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[Rc<NamedMatch>], + ret_val: &mut HashMap<Ident, Rc<NamedMatch>>) { match *m { codemap::Spanned {node: MatchTok(_), .. } => (), codemap::Spanned {node: MatchSeq(ref more_ms, _, _, _, _), .. } => { @@ -189,7 +190,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) p_s.span_diagnostic .span_fatal(span, "duplicated bind name: " + string.get()) } - ret_val.insert(bind_name, res[idx]); + ret_val.insert(bind_name, res[idx].clone()); } } } @@ -199,16 +200,16 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) } pub enum ParseResult { - Success(HashMap<Ident, @NamedMatch>), + Success(HashMap<Ident, Rc<NamedMatch>>), Failure(codemap::Span, ~str), Error(codemap::Span, ~str) } -pub fn parse_or_else<R: Reader>(sess: &ParseSess, - cfg: ast::CrateConfig, - rdr: R, - ms: Vec<Matcher> ) - -> HashMap<Ident, @NamedMatch> { +pub fn parse_or_else(sess: &ParseSess, + cfg: ast::CrateConfig, + rdr: TtReader, + ms: Vec<Matcher> ) + -> HashMap<Ident, Rc<NamedMatch>> { match parse(sess, cfg, rdr, ms.as_slice()) { Success(m) => m, Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), @@ -226,11 +227,11 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { } } -pub fn parse<R: Reader>(sess: &ParseSess, - cfg: ast::CrateConfig, - rdr: R, - ms: &[Matcher]) - -> ParseResult { +pub fn parse(sess: &ParseSess, + cfg: ast::CrateConfig, + mut rdr: TtReader, + ms: &[Matcher]) + -> ParseResult { let mut cur_eis = Vec::new(); cur_eis.push(initial_matcher_pos(ms.iter() .map(|x| (*x).clone()) @@ -282,8 +283,8 @@ pub fn parse<R: Reader>(sess: &ParseSess, let sub = (*ei.matches.get(idx)).clone(); new_pos.matches .get_mut(idx) - .push(@MatchedSeq(sub, mk_sp(ei.sp_lo, - sp.hi))); + .push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo, + sp.hi)))); } new_pos.idx += 1; @@ -325,7 +326,7 @@ pub fn parse<R: Reader>(sess: &ParseSess, for idx in range(match_idx_lo, match_idx_hi) { new_ei.matches .get_mut(idx) - .push(@MatchedSeq(Vec::new(), sp)); + .push(Rc::new(MatchedSeq(Vec::new(), sp))); } cur_eis.push(new_ei); @@ -395,14 +396,14 @@ pub fn parse<R: Reader>(sess: &ParseSess, } rdr.next_token(); } else /* bb_eis.len() == 1 */ { - let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); + let mut rust_parser = Parser(sess, cfg.clone(), ~rdr.clone()); let mut ei = bb_eis.pop().unwrap(); match ei.elts.get(ei.idx).node { MatchNonterminal(_, name, idx) => { let name_string = token::get_ident(name); - ei.matches.get_mut(idx).push(@MatchedNonterminal( - parse_nt(&mut rust_parser, name_string.get()))); + ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal( + parse_nt(&mut rust_parser, name_string.get())))); ei.idx += 1u; } _ => fail!() |
