aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs.tera
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs.tera')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera56
1 files changed, 20 insertions, 36 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera
index f3365c560..03b4bf3a1 100644
--- a/crates/ra_syntax/src/ast/generated.rs.tera
+++ b/crates/ra_syntax/src/ast/generated.rs.tera
@@ -12,18 +12,34 @@ the below applies to the result of this template
12#![cfg_attr(rustfmt, rustfmt_skip)] 12#![cfg_attr(rustfmt, rustfmt_skip)]
13 13
14use crate::{ 14use crate::{
15 SyntaxNode, SyntaxKind::*, 15 SyntaxNode, SyntaxKind::{self, *},
16 ast::{self, AstNode}, 16 ast::{self, AstNode},
17}; 17};
18{% for node, methods in ast %} 18{% for node, methods in ast %}
19// {{ node }} 19// {{ node }}
20
21{%- if methods.enum %}
22#[derive(Debug, Clone, PartialEq, Eq, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct {{ node }} { 21pub struct {{ node }} {
24 pub(crate) syntax: SyntaxNode, 22 pub(crate) syntax: SyntaxNode,
25} 23}
26 24
25impl AstNode for {{ node }} {
26 fn can_cast(kind: SyntaxKind) -> bool {
27 match kind {
28 {%- if methods.enum %}
29 {% for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor -%}
30 {% else %}
31 {{ node | SCREAM }}
32 {%- endif %} => true,
33 _ => false,
34 }
35 }
36 fn cast(syntax: SyntaxNode) -> Option<Self> {
37 if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None }
38 }
39 fn syntax(&self) -> &SyntaxNode { &self.syntax }
40}
41
42{% if methods.enum %}
27#[derive(Debug, Clone, PartialEq, Eq)] 43#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum {{ node }}Kind { 44pub enum {{ node }}Kind {
29{%- for kind in methods.enum %} 45{%- for kind in methods.enum %}
@@ -33,25 +49,9 @@ pub enum {{ node }}Kind {
33 49
34{%- for kind in methods.enum %} 50{%- for kind in methods.enum %}
35impl From<{{ kind }}> for {{ node }} { 51impl From<{{ kind }}> for {{ node }} {
36 fn from(n: {{ kind }}) -> {{ node }} { 52 fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } }
37 {{ node }}::cast(n.syntax).unwrap()
38 }
39} 53}
40{%- endfor %} 54{%- endfor %}
41
42
43impl AstNode for {{ node }} {
44 fn cast(syntax: SyntaxNode) -> Option<Self> {
45 match syntax.kind() {
46 {%- for kind in methods.enum %}
47 | {{ kind | SCREAM }}
48 {%- endfor %} => Some({{ node }} { syntax }),
49 _ => None,
50 }
51 }
52 fn syntax(&self) -> &SyntaxNode { &self.syntax }
53}
54
55impl {{ node }} { 55impl {{ node }} {
56 pub fn kind(&self) -> {{ node }}Kind { 56 pub fn kind(&self) -> {{ node }}Kind {
57 match self.syntax.kind() { 57 match self.syntax.kind() {
@@ -62,22 +62,6 @@ impl {{ node }} {
62 } 62 }
63 } 63 }
64} 64}
65{% else %}
66#[derive(Debug, Clone, PartialEq, Eq, Hash)]
67pub struct {{ node }} {
68 pub(crate) syntax: SyntaxNode,
69}
70
71impl AstNode for {{ node }} {
72 fn cast(syntax: SyntaxNode) -> Option<Self> {
73 match syntax.kind() {
74 {{ node | SCREAM }} => Some({{ node }} { syntax }),
75 _ => None,
76 }
77 }
78 fn syntax(&self) -> &SyntaxNode { &self.syntax }
79}
80
81{% endif %} 65{% endif %}
82{% if methods.traits -%} 66{% if methods.traits -%}
83 67