This commit is contained in:
Jeffrey Seyfried 2017-03-06 06:45:28 +00:00
parent d9cf601ae8
commit 460bf55f8a
2 changed files with 11 additions and 12 deletions

View File

@ -488,7 +488,7 @@ pub fn parse(sess: &ParseSess, tts: TokenStream, ms: &[TokenTree], directory: Op
fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
match name {
"tt" => {
return token::NtTT(panictry!(p.parse_token_tree()));
return token::NtTT(p.parse_token_tree());
}
_ => {}
}

View File

@ -891,7 +891,7 @@ pub fn eat_to_tokens(&mut self, kets: &[&token::Token]) {
self.parse_seq_to_before_tokens(kets,
SeqSep::none(),
|p| p.parse_token_tree(),
|p| Ok(p.parse_token_tree()),
|mut e| handler.cancel(&mut e));
}
@ -1267,7 +1267,7 @@ pub fn parse_trait_item(&mut self) -> PResult<'a, TraitItem> {
break;
}
token::OpenDelim(token::Brace) => {
self.parse_token_tree()?;
self.parse_token_tree();
break;
}
_ => self.bump(),
@ -2101,10 +2101,10 @@ pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinVec<Attribute>) -> P<Expr> {
fn expect_delimited_token_tree(&mut self) -> PResult<'a, (token::DelimToken, ThinTokenStream)> {
match self.token {
token::OpenDelim(delim) => self.parse_token_tree().map(|tree| match tree {
TokenTree::Delimited(_, delimited) => (delim, delimited.stream().into()),
token::OpenDelim(delim) => match self.parse_token_tree() {
TokenTree::Delimited(_, delimited) => Ok((delim, delimited.stream().into())),
_ => unreachable!(),
}),
},
_ => Err(self.fatal("expected open delimiter")),
}
}
@ -2643,24 +2643,23 @@ pub fn check_unknown_macro_variable(&mut self) {
}
/// parse a single token tree from the input.
pub fn parse_token_tree(&mut self) -> PResult<'a, TokenTree> {
pub fn parse_token_tree(&mut self) -> TokenTree {
match self.token {
token::OpenDelim(..) => {
let frame = mem::replace(&mut self.token_cursor.frame,
self.token_cursor.stack.pop().unwrap());
self.span = frame.span;
self.bump();
return Ok(TokenTree::Delimited(frame.span, Delimited {
TokenTree::Delimited(frame.span, Delimited {
delim: frame.delim,
tts: frame.tree_cursor.original_stream().into(),
}));
})
},
token::CloseDelim(_) | token::Eof => unreachable!(),
_ => {
let token = mem::replace(&mut self.token, token::Underscore);
let res = Ok(TokenTree::Token(self.span, token));
self.bump();
res
TokenTree::Token(self.prev_span, token)
}
}
}
@ -2670,7 +2669,7 @@ pub fn parse_token_tree(&mut self) -> PResult<'a, TokenTree> {
pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec<TokenTree>> {
let mut tts = Vec::new();
while self.token != token::Eof {
tts.push(self.parse_token_tree()?);
tts.push(self.parse_token_tree());
}
Ok(tts)
}