From b18d2882f4f05078abfcf0595d08c226860de6c3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 09:55:32 +0300 Subject: Generate accessors --- crates/libsyntax2/src/ast/generated.rs.tera | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 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 afce068c8..86de7bce8 100644 --- a/crates/libsyntax2/src/ast/generated.rs.tera +++ b/crates/libsyntax2/src/ast/generated.rs.tera @@ -21,13 +21,29 @@ impl AstNode for {{ Name }} { } impl {{ Name }} { -{% for (method_name, kind) in node.opts %} -{% set ChildName = kind | camel %} - pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator> + 'a { +{%- if node.collections -%} +{%- for m in node.collections -%} +{%- set method_name = m.0 -%} +{%- set ChildName = m.1 | camel %} + pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator> + 'a { self.syntax() .children() - .filter_map({{ ChildKind }}::cast) + .filter_map({{ ChildName }}::cast) } -{% endfor %} +{% endfor -%} +{%- endif -%} + +{%- if node.options -%} +{%- for m in node.options -%} +{%- set method_name = m.0 -%} +{%- set ChildName = m.1 | camel %} + pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { + self.syntax() + .children() + .filter_map({{ ChildName }}::cast) + .next() + } +{% endfor -%} +{%- endif -%} } {% endfor %} -- cgit v1.2.3