diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-01-29 08:38:44 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-02-28 22:14:29 +0000 |
| commit | d8b34e9a74a4e91c4283ba4002a050ac0150cec6 (patch) | |
| tree | fc62b9e970fd9120e078856dd6c9727bcb55ac89 /src/libsyntax/tokenstream.rs | |
| parent | 247188803356234ae5d6ecf947ffb2308688dc90 (diff) | |
| download | rust-d8b34e9a74a4e91c4283ba4002a050ac0150cec6.tar.gz rust-d8b34e9a74a4e91c4283ba4002a050ac0150cec6.zip | |
Add `syntax::ext::tt::quoted::{TokenTree, ..}` and remove `tokenstream::TokenTree::Sequence`.
Diffstat (limited to 'src/libsyntax/tokenstream.rs')
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index bd63e9f39e5..66654046721 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -12,9 +12,7 @@ //! //! TokenStreams represent syntactic objects before they are converted into ASTs. //! A `TokenStream` is, roughly speaking, a sequence (eg stream) of `TokenTree`s, -//! which are themselves either a single Token, a Delimited subsequence of tokens, -//! or a SequenceRepetition specifier (for the purpose of sequence generation during macro -//! expansion). +//! which are themselves a single `Token` or a `Delimited` subsequence of tokens. //! //! ## Ownership //! TokenStreams are persistent data structures constructed as ropes with reference @@ -28,10 +26,10 @@ use ast::{self, AttrStyle, LitKind}; use syntax_pos::{BytePos, Span, DUMMY_SP}; use codemap::Spanned; use ext::base; -use ext::tt::macro_parser; +use ext::tt::{macro_parser, quoted}; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use parse::{self, Directory}; -use parse::token::{self, Token, Lit, Nonterminal}; +use parse::token::{self, Token, Lit}; use print::pprust; use serialize::{Decoder, Decodable, Encoder, Encodable}; use symbol::Symbol; @@ -84,27 +82,6 @@ impl Delimited { } } -/// A sequence of token trees -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct SequenceRepetition { - /// The sequence of token trees - pub tts: Vec<TokenTree>, - /// The optional separator - pub separator: Option<token::Token>, - /// Whether the sequence can be repeated zero (*), or one or more times (+) - pub op: KleeneOp, - /// The number of `MatchNt`s that appear in the sequence (and subsequences) - pub num_captures: usize, -} - -/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star) -/// for token sequences. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum KleeneOp { - ZeroOrMore, - OneOrMore, -} - /// When the main rust parser encounters a syntax-extension invocation, it /// parses the arguments to the invocation as a token-tree. This is a very /// loose structure, such that all sorts of different AST-fragments can @@ -123,10 +100,6 @@ pub enum TokenTree { Token(Span, token::Token), /// A delimited sequence of token trees Delimited(Span, Rc<Delimited>), - - // This only makes sense in MBE macros. - /// A kleene-style repetition sequence with a span - Sequence(Span, Rc<SequenceRepetition>), } impl TokenTree { @@ -138,15 +111,10 @@ impl TokenTree { AttrStyle::Inner => 3, } } - TokenTree::Token(_, token::Interpolated(ref nt)) => { - if let Nonterminal::NtTT(..) = **nt { 1 } else { 0 } - }, - TokenTree::Token(_, token::MatchNt(..)) => 3, TokenTree::Delimited(_, ref delimed) => match delimed.delim { token::NoDelim => delimed.tts.len(), _ => delimed.tts.len() + 2, }, - TokenTree::Sequence(_, ref seq) => seq.tts.len(), TokenTree::Token(..) => 0, } } @@ -197,30 +165,12 @@ impl TokenTree { } delimed.tts[index - 1].clone() } - (&TokenTree::Token(sp, token::MatchNt(name, kind)), _) => { - let v = [TokenTree::Token(sp, token::SubstNt(name)), - TokenTree::Token(sp, token::Colon), - TokenTree::Token(sp, token::Ident(kind))]; - v[index].clone() - } - (&TokenTree::Sequence(_, ref seq), _) => seq.tts[index].clone(), _ => panic!("Cannot expand a token tree"), } } - /// Returns the `Span` corresponding to this token tree. - pub fn get_span(&self) -> Span { - match *self { - TokenTree::Token(span, _) => span, - TokenTree::Delimited(span, _) => span, - TokenTree::Sequence(span, _) => span, - } - } - /// Use this token tree as a matcher to parse given tts. - pub fn parse(cx: &base::ExtCtxt, - mtch: &[TokenTree], - tts: &[TokenTree]) + pub fn parse(cx: &base::ExtCtxt, mtch: &[quoted::TokenTree], tts: &[TokenTree]) -> macro_parser::NamedParseResult { // `None` is because we're not interpolating let directory = Directory { @@ -252,9 +202,7 @@ impl TokenTree { /// Retrieve the TokenTree's span. pub fn span(&self) -> Span { match *self { - TokenTree::Token(sp, _) | - TokenTree::Delimited(sp, _) | - TokenTree::Sequence(sp, _) => sp, + TokenTree::Token(sp, _) | TokenTree::Delimited(sp, _) => sp, } } |
