From 2e971cdcbbeb543ab6b66dc8558644c1f4a80670 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 10:11:58 +0300 Subject: Use dict for AST --- crates/libsyntax2/src/ast/generated.rs | 3 --- crates/libsyntax2/src/ast/generated.rs.tera | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'crates/libsyntax2/src/ast') 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 { SyntaxKind::*, }; - #[derive(Debug, Clone, Copy)] pub struct File> { syntax: SyntaxNode, @@ -28,7 +27,6 @@ impl File { } } - #[derive(Debug, Clone, Copy)] pub struct Function> { syntax: SyntaxNode, @@ -53,7 +51,6 @@ impl Function { } } - #[derive(Debug, Clone, Copy)] pub struct Name> { syntax: SyntaxNode, 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 { SyntaxNode, SyntaxRoot, TreeRoot, AstNode, SyntaxKind::*, }; -{% for node in ast %} -{% set Name = node.kind | camel %} +{% for node, methods in ast %} #[derive(Debug, Clone, Copy)] -pub struct {{ Name }}> { +pub struct {{ node }}> { syntax: SyntaxNode, } -impl AstNode for {{ Name }} { +impl AstNode for {{ node }} { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - {{ node.kind }} => Some({{ Name }} { syntax }), + {{ node | upper }} => Some({{ node }} { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl {{ Name }} { -{%- if node.collections -%} -{%- for m in node.collections -%} +impl {{ node }} { +{%- if methods.collections -%} +{%- for m in methods.collections -%} {%- set method_name = m.0 -%} -{%- set ChildName = m.1 | camel %} +{%- set ChildName = m.1 %} pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator> + 'a { self.syntax() .children() @@ -33,10 +32,10 @@ impl {{ Name }} { {% endfor -%} {%- endif -%} -{%- if node.options -%} -{%- for m in node.options -%} +{%- if methods.options -%} +{%- for m in methods.options -%} {%- set method_name = m.0 -%} -{%- set ChildName = m.1 | camel %} +{%- set ChildName = m.1 %} pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { self.syntax() .children() -- cgit v1.2.3