Attach TokenStream
to ast::Block
A `Block` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
This commit is contained in:
parent
ad3a6f70ac
commit
de4bd9f0f8
8 changed files with 21 additions and 4 deletions
|
@ -111,7 +111,14 @@ impl<'a> Parser<'a> {
|
|||
return Err(self.struct_span_err(self.token.span, "expected an item keyword"));
|
||||
}
|
||||
},
|
||||
NonterminalKind::Block => token::NtBlock(self.parse_block()?),
|
||||
NonterminalKind::Block => {
|
||||
let (mut block, tokens) = self.collect_tokens(|this| this.parse_block())?;
|
||||
// We have have eaten an NtBlock, which could already have tokens
|
||||
if block.tokens.is_none() {
|
||||
block.tokens = Some(tokens);
|
||||
}
|
||||
token::NtBlock(block)
|
||||
}
|
||||
NonterminalKind::Stmt => match self.parse_stmt()? {
|
||||
Some(s) => token::NtStmt(s),
|
||||
None => return Err(self.struct_span_err(self.token.span, "expected a statement")),
|
||||
|
|
|
@ -411,7 +411,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> {
|
||||
P(Block { stmts, id: DUMMY_NODE_ID, rules, span })
|
||||
P(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None })
|
||||
}
|
||||
|
||||
pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue