Placement refactor (#6034)

## Summary

This PR is a refactoring of placement.rs. The code got more consistent,
some comments were updated and some dead code was removed or replaced
with debug assertions. It also contains a bugfix for the placement of
end-of-branch comments with nested bodies inside try statements that
occurred when refactoring the nested body loop.

## Test Plan

The existing test cases don't change. I added a couple of cases that i
think should be tested but weren't, and a regression test for the bugfix
This commit is contained in:
konsti 2023-07-25 11:49:05 +02:00 committed by GitHub
parent 51d8fc1f30
commit e7f228f781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 383 additions and 352 deletions

View file

@ -4390,6 +4390,16 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::StmtTryStar(_)
)
}
/// In our AST, only some alternative branches are represented as a node. This has historical
/// reasons, e.g. we added a node for elif/else in if statements which was not originally
/// present in the parser.
pub const fn is_alternative_branch_with_node(self) -> bool {
matches!(
self,
AnyNodeRef::ExceptHandlerExceptHandler(_) | AnyNodeRef::ElifElseClause(_)
)
}
}
impl<'a> From<&'a ast::ModModule> for AnyNodeRef<'a> {