Skip to content

Commit

Permalink
Auto merge of rust-lang#34924 - cgswords:empty_delim, r=nrc
Browse files Browse the repository at this point in the history
Added empty CloseDelim to tokens for future use.

Description says it all. I added a new DelimToken type, Empty, to indicate a Delimited tokenstream with no actual delimiters (which are variously useful for constructing macro output).

r? @nrc
  • Loading branch information
bors authored Jul 22, 2016
2 parents af87681 + 536c315 commit ad264f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl<'a> Classifier<'a> {
token::Dot | token::DotDot | token::DotDotDot | token::Comma | token::Semi |
token::Colon | token::ModSep | token::LArrow | token::OpenDelim(_) |
token::CloseDelim(token::Brace) | token::CloseDelim(token::Paren) |
token::CloseDelim(token::NoDelim) |
token::Question => Class::None,
token::Dollar => {
if self.lexer.peek().tok.is_ident() {
Expand Down
7 changes: 4 additions & 3 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,10 @@ fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOpToken) -> P<ast::Expr> {

fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken) -> P<ast::Expr> {
let name = match delim {
token::Paren => "Paren",
token::Bracket => "Bracket",
token::Brace => "Brace",
token::Paren => "Paren",
token::Bracket => "Bracket",
token::Brace => "Brace",
token::NoDelim => "NoDelim",
};
mk_token_path(cx, sp, name)
}
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum DelimToken {
Bracket,
/// A curly brace: `{` or `}`
Brace,
/// An empty delimiter
NoDelim,
}

#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ pub fn token_to_string(tok: &Token) -> String {
token::CloseDelim(token::Bracket) => "]".to_string(),
token::OpenDelim(token::Brace) => "{".to_string(),
token::CloseDelim(token::Brace) => "}".to_string(),
token::OpenDelim(token::NoDelim) => " ".to_string(),
token::CloseDelim(token::NoDelim) => " ".to_string(),
token::Pound => "#".to_string(),
token::Dollar => "$".to_string(),
token::Question => "?".to_string(),
Expand Down Expand Up @@ -1777,12 +1779,14 @@ impl<'a> State<'a> {
try!(self.head(""));
try!(self.bopen());
}
token::NoDelim => {}
}
try!(self.print_tts(&m.node.tts));
match delim {
token::Paren => self.pclose(),
token::Bracket => word(&mut self.s, "]"),
token::Brace => self.bclose(m.span),
token::NoDelim => Ok(()),
}
}

Expand Down

0 comments on commit ad264f7

Please sign in to comment.