aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-11 09:03:22 +0100
committerAleksey Kladov <[email protected]>2018-08-11 09:03:22 +0100
commitd5119133fc03694c6644cac9e307d1d496fc9bf2 (patch)
treec8498441aa91abc5af44ed9f978c98dd419495ab /crates/libsyntax2
parent78f41ea707cc8aeaa8d1ba8a7216cb8712f13e98 (diff)
heck
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs96
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera2
-rw-r--r--crates/libsyntax2/src/grammar.ron20
3 files changed, 117 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index c9b587ecb..7a2a9c7d4 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -5,6 +5,30 @@ use {
5}; 5};
6 6
7#[derive(Debug, Clone, Copy)] 7#[derive(Debug, Clone, Copy)]
8pub struct ConstItem<R: TreeRoot = Arc<SyntaxRoot>> {
9 syntax: SyntaxNode<R>,
10}
11
12impl<R: TreeRoot> AstNode<R> for ConstItem<R> {
13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
14 match syntax.kind() {
15 CONST_ITEM => Some(ConstItem { syntax }),
16 _ => None,
17 }
18 }
19 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
20}
21
22impl<R: TreeRoot> ConstItem<R> {
23 pub fn name(&self) -> Option<Name<R>> {
24 self.syntax()
25 .children()
26 .filter_map(Name::cast)
27 .next()
28 }
29}
30
31#[derive(Debug, Clone, Copy)]
8pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> { 32pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
9 syntax: SyntaxNode<R>, 33 syntax: SyntaxNode<R>,
10} 34}
@@ -76,6 +100,30 @@ impl<R: TreeRoot> Function<R> {
76} 100}
77 101
78#[derive(Debug, Clone, Copy)] 102#[derive(Debug, Clone, Copy)]
103pub struct Module<R: TreeRoot = Arc<SyntaxRoot>> {
104 syntax: SyntaxNode<R>,
105}
106
107impl<R: TreeRoot> AstNode<R> for Module<R> {
108 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
109 match syntax.kind() {
110 MODULE => Some(Module { syntax }),
111 _ => None,
112 }
113 }
114 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
115}
116
117impl<R: TreeRoot> Module<R> {
118 pub fn name(&self) -> Option<Name<R>> {
119 self.syntax()
120 .children()
121 .filter_map(Name::cast)
122 .next()
123 }
124}
125
126#[derive(Debug, Clone, Copy)]
79pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> { 127pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> {
80 syntax: SyntaxNode<R>, 128 syntax: SyntaxNode<R>,
81} 129}
@@ -93,6 +141,30 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
93impl<R: TreeRoot> Name<R> {} 141impl<R: TreeRoot> Name<R> {}
94 142
95#[derive(Debug, Clone, Copy)] 143#[derive(Debug, Clone, Copy)]
144pub struct StaticItem<R: TreeRoot = Arc<SyntaxRoot>> {
145 syntax: SyntaxNode<R>,
146}
147
148impl<R: TreeRoot> AstNode<R> for StaticItem<R> {
149 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
150 match syntax.kind() {
151 STATIC_ITEM => Some(StaticItem { syntax }),
152 _ => None,
153 }
154 }
155 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
156}
157
158impl<R: TreeRoot> StaticItem<R> {
159 pub fn name(&self) -> Option<Name<R>> {
160 self.syntax()
161 .children()
162 .filter_map(Name::cast)
163 .next()
164 }
165}
166
167#[derive(Debug, Clone, Copy)]
96pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> { 168pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
97 syntax: SyntaxNode<R>, 169 syntax: SyntaxNode<R>,
98} 170}
@@ -116,3 +188,27 @@ impl<R: TreeRoot> Struct<R> {
116 } 188 }
117} 189}
118 190
191#[derive(Debug, Clone, Copy)]
192pub struct Trait<R: TreeRoot = Arc<SyntaxRoot>> {
193 syntax: SyntaxNode<R>,
194}
195
196impl<R: TreeRoot> AstNode<R> for Trait<R> {
197 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
198 match syntax.kind() {
199 TRAIT => Some(Trait { syntax }),
200 _ => None,
201 }
202 }
203 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
204}
205
206impl<R: TreeRoot> Trait<R> {
207 pub fn name(&self) -> Option<Name<R>> {
208 self.syntax()
209 .children()
210 .filter_map(Name::cast)
211 .next()
212 }
213}
214
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera
index 09630e427..86b8b05d1 100644
--- a/crates/libsyntax2/src/ast/generated.rs.tera
+++ b/crates/libsyntax2/src/ast/generated.rs.tera
@@ -12,7 +12,7 @@ pub struct {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> {
12impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { 12impl<R: TreeRoot> AstNode<R> for {{ node }}<R> {
13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
14 match syntax.kind() { 14 match syntax.kind() {
15 {{ node | upper }} => Some({{ node }} { syntax }), 15 {{ node | SCREAM }} => Some({{ node }} { syntax }),
16 _ => None, 16 _ => None,
17 } 17 }
18 } 18 }
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index a8916c5c7..c9470d4fa 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -234,6 +234,26 @@ Grammar(
234 ["name", "Name"] 234 ["name", "Name"]
235 ] 235 ]
236 ), 236 ),
237 "Trait": (
238 options: [
239 ["name", "Name"]
240 ]
241 ),
242 "Module": (
243 options: [
244 ["name", "Name"]
245 ]
246 ),
247 "ConstItem": (
248 options: [
249 ["name", "Name"]
250 ]
251 ),
252 "StaticItem": (
253 options: [
254 ["name", "Name"]
255 ]
256 ),
237 "Name": (), 257 "Name": (),
238 }, 258 },
239) 259)