diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-05 14:17:56 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-06 14:04:02 +0300 |
| commit | ff40e37b98fb44366a329d1b0d9642d462cc6ab6 (patch) | |
| tree | 19ba8638a9ad0939e7f918765872f3c4e7c6bec1 /src/libsyntax/ext/tt | |
| parent | 738e14565deb48800c06abc22f8e35e412f10010 (diff) | |
| download | rust-ff40e37b98fb44366a329d1b0d9642d462cc6ab6.tar.gz rust-ff40e37b98fb44366a329d1b0d9642d462cc6ab6.zip | |
Some code cleanup and tidy/test fixes
Diffstat (limited to 'src/libsyntax/ext/tt')
| -rw-r--r-- | src/libsyntax/ext/tt/quoted.rs | 41 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 2 |
2 files changed, 22 insertions, 21 deletions
diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index b4672fb4a58..ec7d7f705d8 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -24,12 +24,12 @@ pub struct Delimited { impl Delimited { /// Returns the opening delimiter (possibly `NoDelim`). - pub fn open_token(&self) -> token::TokenKind { + pub fn open_token(&self) -> TokenKind { token::OpenDelim(self.delim) } /// Returns the closing delimiter (possibly `NoDelim`). - pub fn close_token(&self) -> token::TokenKind { + pub fn close_token(&self) -> TokenKind { token::CloseDelim(self.delim) } @@ -59,7 +59,7 @@ pub struct SequenceRepetition { /// The sequence of token trees pub tts: Vec<TokenTree>, /// The optional separator - pub separator: Option<token::TokenKind>, + pub separator: Option<TokenKind>, /// Whether the sequence can be repeated zero (*), or one or more times (+) pub op: KleeneOp, /// The number of `Match`s that appear in the sequence (and subsequences) @@ -210,20 +210,21 @@ pub fn parse( match tree { TokenTree::MetaVar(start_sp, ident) if expect_matchers => { let span = match trees.next() { - Some(tokenstream::TokenTree::Token(Token { kind: token::Colon, span })) => match trees.next() { - Some(tokenstream::TokenTree::Token(token)) => match token.ident() { - Some((kind, _)) => { - let span = token.span.with_lo(start_sp.lo()); - result.push(TokenTree::MetaVarDecl(span, ident, kind)); - continue; - } - _ => token.span, + Some(tokenstream::TokenTree::Token(Token { kind: token::Colon, span })) => + match trees.next() { + Some(tokenstream::TokenTree::Token(token)) => match token.ident() { + Some((kind, _)) => { + let span = token.span.with_lo(start_sp.lo()); + result.push(TokenTree::MetaVarDecl(span, ident, kind)); + continue; + } + _ => token.span, + }, + tree => tree + .as_ref() + .map(tokenstream::TokenTree::span) + .unwrap_or(span), }, - tree => tree - .as_ref() - .map(tokenstream::TokenTree::span) - .unwrap_or(span), - }, tree => tree .as_ref() .map(tokenstream::TokenTree::span) @@ -370,7 +371,7 @@ where /// Takes a token and returns `Some(KleeneOp)` if the token is `+` `*` or `?`. Otherwise, return /// `None`. -fn kleene_op(token: &token::TokenKind) -> Option<KleeneOp> { +fn kleene_op(token: &TokenKind) -> Option<KleeneOp> { match *token { token::BinOp(token::Star) => Some(KleeneOp::ZeroOrMore), token::BinOp(token::Plus) => Some(KleeneOp::OneOrMore), @@ -423,7 +424,7 @@ fn parse_sep_and_kleene_op<I>( attrs: &[ast::Attribute], edition: Edition, macro_node_id: NodeId, -) -> (Option<token::TokenKind>, KleeneOp) +) -> (Option<TokenKind>, KleeneOp) where I: Iterator<Item = tokenstream::TokenTree>, { @@ -448,7 +449,7 @@ fn parse_sep_and_kleene_op_2015<I>( _features: &Features, _attrs: &[ast::Attribute], macro_node_id: NodeId, -) -> (Option<token::TokenKind>, KleeneOp) +) -> (Option<TokenKind>, KleeneOp) where I: Iterator<Item = tokenstream::TokenTree>, { @@ -566,7 +567,7 @@ fn parse_sep_and_kleene_op_2018<I>( sess: &ParseSess, _features: &Features, _attrs: &[ast::Attribute], -) -> (Option<token::TokenKind>, KleeneOp) +) -> (Option<TokenKind>, KleeneOp) where I: Iterator<Item = tokenstream::TokenTree>, { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index b382893ce4e..90a9cc8f34d 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -242,7 +242,7 @@ pub fn transcribe( Ident::new(ident.name, ident.span.apply_mark(cx.current_expansion.mark)); sp = sp.apply_mark(cx.current_expansion.mark); result.push(TokenTree::token(token::Dollar, sp).into()); - result.push(TokenTree::token(token::TokenKind::from_ast_ident(ident), sp).into()); + result.push(TokenTree::token(TokenKind::from_ast_ident(ident), sp).into()); } } |
