mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Re-integrate RustPython parser repository (#4359)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
865205d992
commit
be6e00ef6e
270 changed files with 3061 additions and 3361 deletions
|
@ -1,7 +1,6 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use rustpython_parser::ast::ExcepthandlerKind::ExceptHandler;
|
||||
use rustpython_parser::ast::{Stmt, StmtKind};
|
||||
use rustpython_parser::ast::{self, ExcepthandlerKind, Stmt, StmtKind};
|
||||
|
||||
use crate::node::{NodeId, Nodes};
|
||||
|
||||
|
@ -43,26 +42,28 @@ fn common_ancestor(
|
|||
/// Return the alternative branches for a given node.
|
||||
fn alternatives(stmt: &Stmt) -> Vec<Vec<&Stmt>> {
|
||||
match &stmt.node {
|
||||
StmtKind::If { body, .. } => vec![body.iter().collect()],
|
||||
StmtKind::Try {
|
||||
StmtKind::If(ast::StmtIf { body, .. }) => vec![body.iter().collect()],
|
||||
StmtKind::Try(ast::StmtTry {
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
..
|
||||
}
|
||||
| StmtKind::TryStar {
|
||||
})
|
||||
| StmtKind::TryStar(ast::StmtTryStar {
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
..
|
||||
} => vec![body.iter().chain(orelse.iter()).collect()]
|
||||
}) => vec![body.iter().chain(orelse.iter()).collect()]
|
||||
.into_iter()
|
||||
.chain(handlers.iter().map(|handler| {
|
||||
let ExceptHandler { body, .. } = &handler.node;
|
||||
let ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler {
|
||||
body, ..
|
||||
}) = &handler.node;
|
||||
body.iter().collect()
|
||||
}))
|
||||
.collect(),
|
||||
StmtKind::Match { cases, .. } => cases
|
||||
StmtKind::Match(ast::StmtMatch { cases, .. }) => cases
|
||||
.iter()
|
||||
.map(|case| case.body.iter().collect())
|
||||
.collect(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue