Handwrite Stmt

This commit is contained in:
Aleksey Kladov 2020-07-31 15:40:48 +02:00
parent 4d38b0dce1
commit a7ca6583fb
4 changed files with 62 additions and 52 deletions

View file

@ -1,6 +1,37 @@
//! This file is actually hand-written, but the submodules are indeed generated.
#[rustfmt::skip]
mod nodes;
#[rustfmt::skip]
mod tokens;
#[rustfmt::skip]
pub(super) mod nodes;
#[rustfmt::skip]
pub(super) mod tokens;
use crate::{
AstNode,
SyntaxKind::{self, *},
SyntaxNode,
};
pub use {nodes::*, tokens::*};
// Stmt is the only nested enum, so it's easier to just hand-write it
impl AstNode for Stmt {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
LET_STMT | EXPR_STMT => true,
_ => false,
}
}
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,
};
Some(res)
}
fn syntax(&self) -> &SyntaxNode {
match self {
Stmt::LetStmt(it) => &it.syntax,
Stmt::ExprStmt(it) => &it.syntax,
}
}
}