aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast/generated.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast/generated.rs')
-rw-r--r--crates/syntax/src/ast/generated.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/generated.rs b/crates/syntax/src/ast/generated.rs
new file mode 100644
index 000000000..4a6f41ee7
--- /dev/null
+++ b/crates/syntax/src/ast/generated.rs
@@ -0,0 +1,41 @@
1//! This file is actually hand-written, but the submodules are indeed generated.
2#[rustfmt::skip]
3mod nodes;
4#[rustfmt::skip]
5mod tokens;
6
7use crate::{
8 AstNode,
9 SyntaxKind::{self, *},
10 SyntaxNode,
11};
12
13pub use {nodes::*, tokens::*};
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}