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.tera | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/libsyntax2/src/ast/generated.rs.tera') 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