From 936d999b5270d186df28123a5dbd6d2bb848bb2c Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 29 Oct 2014 21:37:54 +1100 Subject: Use common variants for open and close delimiters This common representation for delimeters should make pattern matching easier. Having a separate `token::DelimToken` enum also allows us to enforce the invariant that the opening and closing delimiters must be the same in `ast::TtDelimited`, removing the need to ensure matched delimiters when working with token trees. --- src/libsyntax/print/pprust.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/libsyntax/print') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d347d0199a7..6df9fff0e6b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -225,12 +225,12 @@ pub fn token_to_string(tok: &Token) -> String { token::RArrow => "->".into_string(), token::LArrow => "<-".into_string(), token::FatArrow => "=>".into_string(), - token::LParen => "(".into_string(), - token::RParen => ")".into_string(), - token::LBracket => "[".into_string(), - token::RBracket => "]".into_string(), - token::LBrace => "{".into_string(), - token::RBrace => "}".into_string(), + token::OpenDelim(token::Paren) => "(".into_string(), + token::CloseDelim(token::Paren) => ")".into_string(), + token::OpenDelim(token::Bracket) => "[".into_string(), + token::CloseDelim(token::Bracket) => "]".into_string(), + token::OpenDelim(token::Brace) => "{".into_string(), + token::CloseDelim(token::Brace) => "}".into_string(), token::Pound => "#".into_string(), token::Dollar => "$".into_string(), token::Question => "?".into_string(), @@ -1121,12 +1121,11 @@ impl<'a> State<'a> { pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> { match *tt { ast::TtDelimited(_, ref delimed) => { - let (ref open, ref tts, ref close) = **delimed; - try!(word(&mut self.s, token_to_string(&open.token).as_slice())); + try!(word(&mut self.s, token_to_string(&delimed.open_token()).as_slice())); try!(space(&mut self.s)); - try!(self.print_tts(tts.as_slice())); + try!(self.print_tts(delimed.tts.as_slice())); try!(space(&mut self.s)); - word(&mut self.s, token_to_string(&close.token).as_slice()) + word(&mut self.s, token_to_string(&delimed.close_token()).as_slice()) }, ast::TtToken(_, ref tk) => { try!(word(&mut self.s, token_to_string(tk).as_slice())); -- cgit 1.4.1-3-g733a5