aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-31 14:40:48 +0100
committerAleksey Kladov <[email protected]>2020-07-31 14:40:48 +0100
commita7ca6583fbce6f1bddce7b31ad5bb1fc0665b616 (patch)
treeb148be3186c9de3de526fe798eac36f27517c178 /crates/ra_syntax/src/ast/generated.rs
parent4d38b0dce1884dab0da7394ccc979eef0a21076c (diff)
Handwrite Stmt
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
1 files changed, 34 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index f5199e09f..ba55f1c42 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1,6 +1,37 @@
1//! This file is actually hand-written, but the submodules are indeed generated. 1//! This file is actually hand-written, but the submodules are indeed generated.
2
3#[rustfmt::skip] 2#[rustfmt::skip]
4pub(super) mod nodes; 3mod nodes;
5#[rustfmt::skip] 4#[rustfmt::skip]
6pub(super) mod tokens; 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 _ => false,
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 _ => return None,
28 };
29 Some(res)
30 }
31 fn syntax(&self) -> &SyntaxNode {
32 match self {
33 Stmt::LetStmt(it) => &it.syntax,
34 Stmt::ExprStmt(it) => &it.syntax,
35 }
36 }
37}