aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_syntax/src/ast/generated.rs
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs41
1 files changed, 38 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index f5199e09f..4a6f41ee7 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1,6 +1,41 @@
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 _ => 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}