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);
}
let frame = &self.token_cursor.frame;
match frame.tree_cursor.look_ahead(dist - 1) {
Some(tree) => match tree {
TokenTree::Token(token) => looker(token),
TokenTree::Delimited(dspan, delim, _) => {
looker(&Token::new(token::OpenDelim(*delim), dspan.open))
}
},
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)),
let mut cursor = self.token_cursor.clone();
let mut i = 0;
let mut token = Token::dummy();
while i < dist {
token = cursor.next().0;
if matches!(
token.kind,
token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim)
) {
continue;
}
i += 1;
}
return looker(&token);
}
/// 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() {}