aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-11 08:11:58 +0100
committerAleksey Kladov <[email protected]>2018-08-11 08:11:58 +0100
commit2e971cdcbbeb543ab6b66dc8558644c1f4a80670 (patch)
tree61facd6dbdcdf00bbbbda503cc3b78826e63af07 /crates/libsyntax2/src/ast
parente69c70e2a208fd89d4d49a104f5516c55546309e (diff)
Use dict for AST
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs3
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera23
2 files changed, 11 insertions, 15 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()