syntax/ast/
generated.rs

1//! This file is actually hand-written, but the submodules are indeed generated.
2#[rustfmt::skip]
3pub(crate) mod nodes;
4#[rustfmt::skip]
5pub(crate) mod tokens;
6
7use crate::{
8    AstNode,
9    SyntaxKind::{self, *},
10    SyntaxNode,
11};
12
13pub(crate) use nodes::*;
14
15// Stmt is the only nested enum, so it's easier to just hand-write it
16impl AstNode for Stmt {
17    fn can_cast(kind: SyntaxKind) -> bool {
18        match kind {
19            LET_STMT | EXPR_STMT => true,
20            _ => Item::can_cast(kind),
21        }
22    }
23    fn cast(syntax: SyntaxNode) -> Option<Self> {
24        let res = match syntax.kind() {
25            LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
26            EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
27            _ => {
28                let item = Item::cast(syntax)?;
29                Stmt::Item(item)
30            }
31        };
32        Some(res)
33    }
34    fn syntax(&self) -> &SyntaxNode {
35        match self {
36            Stmt::LetStmt(it) => &it.syntax,
37            Stmt::ExprStmt(it) => &it.syntax,
38            Stmt::Item(it) => it.syntax(),
39        }
40    }
41}