1
Fork 0

Fix lookahead with None-delimited group

This commit is contained in:
Aaron Hill 2021-04-12 11:15:38 -04:00
parent c18c0ad2bc
commit eb7b1a150f
No known key found for this signature in database
GPG key ID: B4087E510E98B164
2 changed files with 28 additions and 9 deletions

View file

@ -929,16 +929,20 @@ impl<'a> Parser<'a> {
return looker(&self.token); return looker(&self.token);
} }
let frame = &self.token_cursor.frame; let mut cursor = self.token_cursor.clone();
match frame.tree_cursor.look_ahead(dist - 1) { let mut i = 0;
Some(tree) => match tree { let mut token = Token::dummy();
TokenTree::Token(token) => looker(token), while i < dist {
TokenTree::Delimited(dspan, delim, _) => { token = cursor.next().0;
looker(&Token::new(token::OpenDelim(*delim), dspan.open)) if matches!(
} token.kind,
}, token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim)
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)), ) {
continue;
}
i += 1;
} }
return looker(&token);
} }
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one. /// Returns whether any of the given keywords are `dist` tokens ahead of the current one.

View file

@ -0,0 +1,15 @@
// check-pass
macro_rules! make_struct {
($name:ident) => {
#[derive(Debug)]
struct Foo {
#[cfg(not(FALSE))]
field: fn($name: bool)
}
}
}
make_struct!(param_name);
fn main() {}