Item is a Stmt

This commit is contained in:
Aleksey Kladov 2020-07-31 15:46:12 +02:00
parent a7ca6583fb
commit d4d986c7f8
6 changed files with 36 additions and 15 deletions

View file

@ -17,14 +17,17 @@ impl AstNode for Stmt {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LET_STMT | EXPR_STMT => true,
_ => false,
_ => Item::can_cast(kind),
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() {
LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
_ => return None,
_ => {
let item = Item::cast(syntax)?;
Stmt::Item(item)
}
};
Some(res)
}
@ -32,6 +35,7 @@ impl AstNode for Stmt {
match self {
Stmt::LetStmt(it) => &it.syntax,
Stmt::ExprStmt(it) => &it.syntax,
Stmt::Item(it) => it.syntax(),
}
}
}