aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs3
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera23
-rw-r--r--crates/libsyntax2/src/grammar.ron18
3 files changed, 18 insertions, 26 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 0767df334..12e5a1c3e 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -4,7 +4,6 @@ use {
4 SyntaxKind::*, 4 SyntaxKind::*,
5}; 5};
6 6
7
8#[derive(Debug, Clone, Copy)] 7#[derive(Debug, Clone, Copy)]
9pub struct File<R: TreeRoot = Arc<SyntaxRoot>> { 8pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
10 syntax: SyntaxNode<R>, 9 syntax: SyntaxNode<R>,
@@ -28,7 +27,6 @@ impl<R: TreeRoot> File<R> {
28 } 27 }
29} 28}
30 29
31
32#[derive(Debug, Clone, Copy)] 30#[derive(Debug, Clone, Copy)]
33pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> { 31pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> {
34 syntax: SyntaxNode<R>, 32 syntax: SyntaxNode<R>,
@@ -53,7 +51,6 @@ impl<R: TreeRoot> Function<R> {
53 } 51 }
54} 52}
55 53
56
57#[derive(Debug, Clone, Copy)] 54#[derive(Debug, Clone, Copy)]
58pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> { 55pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> {
59 syntax: SyntaxNode<R>, 56 syntax: SyntaxNode<R>,
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera
index 86de7bce8..09630e427 100644
--- a/crates/libsyntax2/src/ast/generated.rs.tera
+++ b/crates/libsyntax2/src/ast/generated.rs.tera
@@ -3,28 +3,27 @@ use {
3 SyntaxNode, SyntaxRoot, TreeRoot, AstNode, 3 SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
4 SyntaxKind::*, 4 SyntaxKind::*,
5}; 5};
6{% for node in ast %} 6{% for node, methods in ast %}
7{% set Name = node.kind | camel %}
8#[derive(Debug, Clone, Copy)] 7#[derive(Debug, Clone, Copy)]
9pub struct {{ Name }}<R: TreeRoot = Arc<SyntaxRoot>> { 8pub struct {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> {
10 syntax: SyntaxNode<R>, 9 syntax: SyntaxNode<R>,
11} 10}
12 11
13impl<R: TreeRoot> AstNode<R> for {{ Name }}<R> { 12impl<R: TreeRoot> AstNode<R> for {{ node }}<R> {
14 fn cast(syntax: SyntaxNode<R>) -> Option<Self> { 13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
15 match syntax.kind() { 14 match syntax.kind() {
16 {{ node.kind }} => Some({{ Name }} { syntax }), 15 {{ node | upper }} => Some({{ node }} { syntax }),
17 _ => None, 16 _ => None,
18 } 17 }
19 } 18 }
20 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } 19 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
21} 20}
22 21
23impl<R: TreeRoot> {{ Name }}<R> { 22impl<R: TreeRoot> {{ node }}<R> {
24{%- if node.collections -%} 23{%- if methods.collections -%}
25{%- for m in node.collections -%} 24{%- for m in methods.collections -%}
26{%- set method_name = m.0 -%} 25{%- set method_name = m.0 -%}
27{%- set ChildName = m.1 | camel %} 26{%- set ChildName = m.1 %}
28 pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildName }}<R>> + 'a { 27 pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildName }}<R>> + 'a {
29 self.syntax() 28 self.syntax()
30 .children() 29 .children()
@@ -33,10 +32,10 @@ impl<R: TreeRoot> {{ Name }}<R> {
33{% endfor -%} 32{% endfor -%}
34{%- endif -%} 33{%- endif -%}
35 34
36{%- if node.options -%} 35{%- if methods.options -%}
37{%- for m in node.options -%} 36{%- for m in methods.options -%}
38{%- set method_name = m.0 -%} 37{%- set method_name = m.0 -%}
39{%- set ChildName = m.1 | camel %} 38{%- set ChildName = m.1 %}
40 pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}<R>> { 39 pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}<R>> {
41 self.syntax() 40 self.syntax()
42 .children() 41 .children()
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 06a4eb6a7..650f72212 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -213,21 +213,17 @@ Grammar(
213 "SELF_PARAM", 213 "SELF_PARAM",
214 "ARG_LIST", 214 "ARG_LIST",
215 ], 215 ],
216 ast: [ 216 ast: {
217 ( 217 "File": (
218 kind: "FILE",
219 collections: [ 218 collections: [
220 ["functions", "FUNCTION"] 219 ["functions", "Function"]
221 ] 220 ]
222 ), 221 ),
223 ( 222 "Function": (
224 kind: "FUNCTION",
225 options: [ 223 options: [
226 ["name", "NAME"] 224 ["name", "Name"]
227 ] 225 ]
228 ), 226 ),
229 ( 227 "Name": (),
230 kind: "NAME" 228 },
231 ),
232 ]
233) 229)