internal: more reasonable grammar for blocks
Consider these expples
{ 92 }
async { 92 }
'a: { 92 }
#[a] { 92 }
Previously the tree for them were
BLOCK_EXPR
{ ... }
EFFECT_EXPR
async
BLOCK_EXPR
{ ... }
EFFECT_EXPR
'a:
BLOCK_EXPR
{ ... }
BLOCK_EXPR
#[a]
{ ... }
As you see, it gets progressively worse :) The last two items are
especially odd. The last one even violates the balanced curleys
invariant we have (#10357) The new approach is to say that the stuff in
`{}` is stmt_list, and the block is stmt_list + optional modifiers
BLOCK_EXPR
STMT_LIST
{ ... }
BLOCK_EXPR
async
STMT_LIST
{ ... }
BLOCK_EXPR
'a:
STMT_LIST
{ ... }
BLOCK_EXPR
#[a]
STMT_LIST
{ ... }
This commit is contained in:
@@ -162,8 +162,8 @@ fn ws_before(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
|
||||
}
|
||||
|
||||
if prev.kind() == T!['{'] && ast::Stmt::can_cast(new.kind()) {
|
||||
if let Some(block_expr) = prev.parent().and_then(ast::BlockExpr::cast) {
|
||||
let mut indent = IndentLevel::from_element(&block_expr.syntax().clone().into());
|
||||
if let Some(stmt_list) = prev.parent().and_then(ast::StmtList::cast) {
|
||||
let mut indent = IndentLevel::from_element(&stmt_list.syntax().clone().into());
|
||||
indent.0 += 1;
|
||||
return Some(make::tokens::whitespace(&format!("\n{}", indent)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user