mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
visitor-less scopes
This commit is contained in:
parent
8b0298ce09
commit
c16530c988
3 changed files with 49 additions and 17 deletions
|
@ -116,9 +116,13 @@ impl<'a> AstNode<'a> for Block<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Block<'a> {
|
||||
pub fn let_stmts(self) -> impl Iterator<Item = LetStmt<'a>> + 'a {
|
||||
pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
// BlockExpr
|
||||
|
@ -1370,6 +1374,31 @@ impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
|
|||
impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
|
||||
impl<'a> StaticDef<'a> {}
|
||||
|
||||
// Stmt
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Stmt<'a> {
|
||||
ExprStmt(ExprStmt<'a>),
|
||||
LetStmt(LetStmt<'a>),
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for Stmt<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })),
|
||||
LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> {
|
||||
match self {
|
||||
Stmt::ExprStmt(inner) => inner.syntax(),
|
||||
Stmt::LetStmt(inner) => inner.syntax(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Stmt<'a> {}
|
||||
|
||||
// StructDef
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct StructDef<'a> {
|
||||
|
|
|
@ -437,9 +437,13 @@ Grammar(
|
|||
["pat", "Pat"],
|
||||
["initializer", "Expr"],
|
||||
]),
|
||||
"Stmt": (
|
||||
enum: ["ExprStmt", "LetStmt"],
|
||||
),
|
||||
"Block": (
|
||||
options: [["expr", "Expr"]],
|
||||
collections: [
|
||||
["let_stmts", "LetStmt"],
|
||||
["statements", "Stmt"],
|
||||
]
|
||||
),
|
||||
"ParamList": (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue