pub fn parse_token_tree(&mut self) -> PResult<'a, TokenTree> {
        // FIXME #6994: currently, this is too eager. It
        // parses token trees but also identifies TokenType::Sequence's
        // and token::SubstNt's; it's too early to know yet
        // whether something will be a nonterminal or a seq
        // yet.
        maybe_whole!(deref self, NtTT);

        match self.token {
            token::Eof => {
                let mut err: DiagnosticBuilder<'a> =
                    self.diagnostic().struct_span_err(self.span,
                                                      "this file contains an un-closed delimiter");
                for sp in &self.open_braces {
                    err.span_help(*sp, "did you mean to close this delimiter?");
                }

                Err(err)
            },
            token::OpenDelim(delim) => {
                // The span for beginning of the delimited section
                let pre_span = self.span;

                // Parse the open delimiter.
                self.open_braces.push(self.span);
                let open_span = self.span;
                self.bump();

                // Parse the token trees within the delimiters
                let tts = self.parse_seq_to_before_end(&token::CloseDelim(delim),
                                                       SeqSep::none(),
                                                       |p| p.parse_token_tree());

                // Parse the close delimiter.
                let close_span = self.span;
                self.bump();
                self.open_braces.pop().unwrap();

                // Expand to cover the entire delimited token tree
                let span = Span { hi: close_span.hi, ..pre_span };

                Ok(TokenTree::Delimited(span, Rc::new(Delimited {
                    delim: delim,
                    open_span: open_span,
                    tts: tts,
                    close_span: close_span,
                })))
            },
            _ => {
                // invariants: the current token is not a left-delimiter,
                // not an EOF, and not the desired right-delimiter (if
                // it were, parse_seq_to_before_end would have prevented
                // reaching this point.
                maybe_whole!(deref self, NtTT);
                match self.token {
                    token::CloseDelim(_) => {
                        let token_str = self.this_token_to_string();
                        let mut err = self.diagnostic().struct_span_err(self.span,
                            &format!("incorrect close delimiter: `{}`", token_str));
                        // This is a conservative error: only report the last unclosed delimiter.
                        // The previous unclosed delimiters could actually be closed! The parser
                        // just hasn't gotten to them yet.
                        if let Some(&sp) = self.open_braces.last() {
                            err.span_note(sp, "unclosed delimiter");
                        };

                        Err(err)
                    },
                    /* we ought to allow different depths of unquotation */
                    token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => {
                        self.parse_unquoted()
                    }
                    _ => {
                        Ok(TokenTree::Token(self.span, self.bump_and_get()))
                    }
                }
            }
        }
    }
/// parse a single token tree from the input.
parse a single token tree from the input.
parse a single token tree from the input .
pub fn parse_token_tree(&mut self) -> PResult<'a, TokenTree> {
        // FIXME #6994: currently, this is too eager. It
        // parses token trees but also identifies TokenType::Sequence's
        // and token::SubstNt's; it's too early to know yet
        // whether something will be a nonterminal or a seq
        // yet.
        maybe_whole!(deref self, NtTT);
        match self.token {
            token::Eof => {
                let mut err: DiagnosticBuilder<'a> =
                    self.diagnostic().struct_span_err(self.span,
                                                      "this file contains an un-closed delimiter");
                for sp in &self.open_braces {
                    err.span_help(*sp, "did you mean to close this delimiter?");
                }
                Err(err)
            },
            token::OpenDelim(delim) => {
                // The span for beginning of the delimited section
                let pre_span = self.span;
                // Parse the open delimiter.
                self.open_braces.push(self.span);
                let open_span = self.span;
                self.bump();
                // Parse the token trees within the delimiters
                let tts = self.parse_seq_to_before_end(&token::CloseDelim(delim),
                                                       SeqSep::none(),
                                                       |p| p.parse_token_tree());
                // Parse the close delimiter.
                let close_span = self.span;
                self.bump();
                self.open_braces.pop().unwrap();
                // Expand to cover the entire delimited token tree
                let span = Span { hi: close_span.hi, ..pre_span };
                Ok(TokenTree::Delimited(span, Rc::new(Delimited {
                    delim: delim,
                    open_span: open_span,
                    tts: tts,
                    close_span: close_span,
                })))
            },
            _ => {
                // invariants: the current token is not a left-delimiter,
                // not an EOF, and not the desired right-delimiter (if
                // it were, parse_seq_to_before_end would have prevented
                // reaching this point.
                maybe_whole!(deref self, NtTT);
                match self.token {
                    token::CloseDelim(_) => {
                        let token_str = self.this_token_to_string();
                        let mut err = self.diagnostic().struct_span_err(self.span,
                            &format!("incorrect close delimiter: `{}`", token_str));
                        // This is a conservative error: only report the last unclosed delimiter.
                        // The previous unclosed delimiters could actually be closed! The parser
                        // just hasn't gotten to them yet.
                        if let Some(&sp) = self.open_braces.last() {
                            err.span_note(sp, "unclosed delimiter");
                        };
                        Err(err)
                    },
                    /* we ought to allow different depths of unquotation */
                    token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => {
                        self.parse_unquoted()
                    }
                    _ => {
                        Ok(TokenTree::Token(self.span, self.bump_and_get()))
                    }
                }
            }
        }
    }
pub fn parse_token_tree ( & mut self ) -> PResult < ' a , TokenTree > { // FIXME #6994: currently, this is too eager. It // parses token trees but also identifies TokenType::Sequence's // and token::SubstNt's; it's too early to know yet // whether something will be a nonterminal or a seq // yet. maybe_whole ! ( deref self NtTT ) ; match self . token { token :: Eof => { let mut err : DiagnosticBuilder < ' a > = self . diagnostic ( ) . struct_span_err ( self . span , " " ) ; for sp in & self . open_braces { err . span_help ( * sp , " " ) ; } Err ( err ) } , token :: OpenDelim ( delim ) => { // The span for beginning of the delimited section let pre_span = self . span ; // Parse the open delimiter. self . open_braces . push ( self . span ) ; let open_span = self . span ; self . bump ( ) ; // Parse the token trees within the delimiters let tts = self . parse_seq_to_before_end ( & token :: CloseDelim ( delim ) , SeqSep :: none ( ) , | p | p . parse_token_tree ( ) ) ; // Parse the close delimiter. let close_span = self . span ; self . bump ( ) ; self . open_braces . pop ( ) . unwrap ( ) ; // Expand to cover the entire delimited token tree let span = Span { hi : close_span . hi , .. pre_span } ; Ok ( TokenTree :: Delimited ( span , Rc :: new ( Delimited { delim : delim , open_span : open_span , tts : tts , close_span : close_span , } ) ) ) } , _ => { // invariants: the current token is not a left-delimiter, // not an EOF, and not the desired right-delimiter (if // it were, parse_seq_to_before_end would have prevented // reaching this point. maybe_whole ! ( deref self NtTT ) ; match self . token { token :: CloseDelim ( _ ) => { let token_str = self . this_token_to_string ( ) ; let mut err = self . diagnostic ( ) . struct_span_err ( self . span , & format ! ( " " token_str ) ) ; // This is a conservative error: only report the last unclosed delimiter. // The previous unclosed delimiters could actually be closed! The parser // just hasn't gotten to them yet. if let Some ( & sp ) = self . open_braces . last ( ) { err . span_note ( sp , " " ) ; } ; Err ( err ) } , /* we ought to allow different depths of unquotation */ token :: Dollar | token :: SubstNt ( .. ) if self . quote_depth > 0 => { self . parse_unquoted ( ) } _ => { Ok ( TokenTree :: Token ( self . span , self . bump_and_get ( ) ) ) } } } } }
parse a single token tree from the input.
parse a single token tree from the input .
&mut self
&mut self