aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs.tera
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-18 17:23:05 +0100
committerAleksey Kladov <[email protected]>2019-07-19 11:16:24 +0100
commitd402974aa0af6de290245a9d2a69a5d56c4fa610 (patch)
treedf4a0e38e548f9f74592e00a2c5a7d37bab3c4c2 /crates/ra_syntax/src/ast/generated.rs.tera
parent58d4983ba5745975446d60f2886d96f8d2adf0f2 (diff)
migrate ra_syntax to the new rowan API
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs.tera')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera51
1 files changed, 15 insertions, 36 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera
index c8a13fc5f..f3365c560 100644
--- a/crates/ra_syntax/src/ast/generated.rs.tera
+++ b/crates/ra_syntax/src/ast/generated.rs.tera
@@ -11,94 +11,73 @@ the below applies to the result of this template
11 11
12#![cfg_attr(rustfmt, rustfmt_skip)] 12#![cfg_attr(rustfmt, rustfmt_skip)]
13 13
14use rowan::TransparentNewType;
15
16use crate::{ 14use crate::{
17 SyntaxNode, SyntaxKind::*, 15 SyntaxNode, SyntaxKind::*,
18 syntax_node::{TreeArc},
19 ast::{self, AstNode}, 16 ast::{self, AstNode},
20}; 17};
21{% for node, methods in ast %} 18{% for node, methods in ast %}
22// {{ node }} 19// {{ node }}
23 20
24{%- if methods.enum %} 21{%- if methods.enum %}
25#[derive(Debug, PartialEq, Eq, Hash)] 22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26#[repr(transparent)]
27pub struct {{ node }} { 23pub struct {{ node }} {
28 pub(crate) syntax: SyntaxNode, 24 pub(crate) syntax: SyntaxNode,
29} 25}
30unsafe impl TransparentNewType for {{ node }} {
31 type Repr = rowan::SyntaxNode;
32}
33 26
34#[derive(Debug, Clone, Copy, PartialEq, Eq)] 27#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum {{ node }}Kind<'a> { 28pub enum {{ node }}Kind {
36{%- for kind in methods.enum %} 29{%- for kind in methods.enum %}
37 {{ kind }}(&'a {{ kind }}), 30 {{ kind }}({{ kind }}),
38{%- endfor %} 31{%- endfor %}
39} 32}
40 33
41{%- for kind in methods.enum %} 34{%- for kind in methods.enum %}
42impl<'a> From<&'a {{ kind }}> for &'a {{ node }} { 35impl From<{{ kind }}> for {{ node }} {
43 fn from(n: &'a {{ kind }}) -> &'a {{ node }} { 36 fn from(n: {{ kind }}) -> {{ node }} {
44 {{ node }}::cast(&n.syntax).unwrap() 37 {{ node }}::cast(n.syntax).unwrap()
45 } 38 }
46} 39}
47{%- endfor %} 40{%- endfor %}
48 41
49 42
50impl AstNode for {{ node }} { 43impl AstNode for {{ node }} {
51 fn cast(syntax: &SyntaxNode) -> Option<&Self> { 44 fn cast(syntax: SyntaxNode) -> Option<Self> {
52 match syntax.kind() { 45 match syntax.kind() {
53 {%- for kind in methods.enum %} 46 {%- for kind in methods.enum %}
54 | {{ kind | SCREAM }} 47 | {{ kind | SCREAM }}
55 {%- endfor %} => Some({{ node }}::from_repr(syntax.into_repr())), 48 {%- endfor %} => Some({{ node }} { syntax }),
56 _ => None, 49 _ => None,
57 } 50 }
58 } 51 }
59 fn syntax(&self) -> &SyntaxNode { &self.syntax } 52 fn syntax(&self) -> &SyntaxNode { &self.syntax }
60} 53}
61 54
62impl ToOwned for {{ node }} {
63 type Owned = TreeArc<{{ node }}>;
64 fn to_owned(&self) -> TreeArc<{{ node }}> { TreeArc::cast(self.syntax.to_owned()) }
65}
66
67impl {{ node }} { 55impl {{ node }} {
68 pub fn kind(&self) -> {{ node }}Kind { 56 pub fn kind(&self) -> {{ node }}Kind {
69 match self.syntax.kind() { 57 match self.syntax.kind() {
70 {%- for kind in methods.enum %} 58 {%- for kind in methods.enum %}
71 {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(&self.syntax).unwrap()), 59 {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()),
72 {%- endfor %} 60 {%- endfor %}
73 _ => unreachable!(), 61 _ => unreachable!(),
74 } 62 }
75 } 63 }
76} 64}
77{% else %} 65{% else %}
78#[derive(Debug, PartialEq, Eq, Hash)] 66#[derive(Debug, Clone, PartialEq, Eq, Hash)]
79#[repr(transparent)]
80pub struct {{ node }} { 67pub struct {{ node }} {
81 pub(crate) syntax: SyntaxNode, 68 pub(crate) syntax: SyntaxNode,
82} 69}
83unsafe impl TransparentNewType for {{ node }} {
84 type Repr = rowan::SyntaxNode;
85}
86 70
87impl AstNode for {{ node }} { 71impl AstNode for {{ node }} {
88 fn cast(syntax: &SyntaxNode) -> Option<&Self> { 72 fn cast(syntax: SyntaxNode) -> Option<Self> {
89 match syntax.kind() { 73 match syntax.kind() {
90 {{ node | SCREAM }} => Some({{ node }}::from_repr(syntax.into_repr())), 74 {{ node | SCREAM }} => Some({{ node }} { syntax }),
91 _ => None, 75 _ => None,
92 } 76 }
93 } 77 }
94 fn syntax(&self) -> &SyntaxNode { &self.syntax } 78 fn syntax(&self) -> &SyntaxNode { &self.syntax }
95} 79}
96 80
97impl ToOwned for {{ node }} {
98 type Owned = TreeArc<{{ node }}>;
99 fn to_owned(&self) -> TreeArc<{{ node }}> { TreeArc::cast(self.syntax.to_owned()) }
100}
101
102{% endif %} 81{% endif %}
103{% if methods.traits -%} 82{% if methods.traits -%}
104 83
@@ -113,7 +92,7 @@ impl {{ node }} {
113{%- for m in methods.collections -%} 92{%- for m in methods.collections -%}
114{%- set method_name = m.0 -%} 93{%- set method_name = m.0 -%}
115{%- set ChildName = m.1 %} 94{%- set ChildName = m.1 %}
116 pub fn {{ method_name }}(&self) -> impl Iterator<Item = &{{ ChildName }}> { 95 pub fn {{ method_name }}(&self) -> impl Iterator<Item = {{ ChildName }}> {
117 super::children(self) 96 super::children(self)
118 } 97 }
119{% endfor -%} 98{% endfor -%}
@@ -129,7 +108,7 @@ impl {{ node }} {
129{%- set method_name = m.0 -%} 108{%- set method_name = m.0 -%}
130{%- set ChildName = m.1 %} 109{%- set ChildName = m.1 %}
131{%- endif %} 110{%- endif %}
132 pub fn {{ method_name }}(&self) -> Option<&{{ ChildName }}> { 111 pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> {
133 super::child_opt(self) 112 super::child_opt(self)
134 } 113 }
135{% endfor -%} 114{% endfor -%}