From d3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 22:00:13 +0300 Subject: Borrowed AST --- crates/libsyntax2/src/ast/generated.rs.tera | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 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 f83da0326..0572cceaa 100644 --- a/crates/libsyntax2/src/ast/generated.rs.tera +++ b/crates/libsyntax2/src/ast/generated.rs.tera @@ -1,21 +1,20 @@ -use std::sync::Arc; use { ast, - SyntaxNode, SyntaxRoot, TreeRoot, AstNode, + SyntaxNodeRef, AstNode, SyntaxKind::*, }; {% for node, methods in ast %} // {{ node }} {%- if methods.enum %} #[derive(Debug, Clone, Copy)] -pub enum {{ node }}> { +pub enum {{ node }}<'a> { {%- for kind in methods.enum %} - {{ kind }}({{ kind }}), + {{ kind }}({{ kind }}<'a>), {%- endfor %} } -impl AstNode for {{ node }} { - fn cast(syntax: SyntaxNode) -> Option { +impl<'a> AstNode<'a> for {{ node }}<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { match syntax.kind() { {%- for kind in methods.enum %} {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), @@ -23,7 +22,7 @@ impl AstNode for {{ node }} { _ => None, } } - fn syntax(&self) -> &SyntaxNode { + fn syntax(self) -> SyntaxNodeRef<'a> { match self { {%- for kind in methods.enum %} {{ node }}::{{ kind }}(inner) => inner.syntax(), @@ -33,32 +32,32 @@ impl AstNode for {{ node }} { } {% else %} #[derive(Debug, Clone, Copy)] -pub struct {{ node }}> { - syntax: SyntaxNode, +pub struct {{ node }}<'a> { + syntax: SyntaxNodeRef<'a>, } -impl AstNode for {{ node }} { - fn cast(syntax: SyntaxNode) -> Option { +impl<'a> AstNode<'a> for {{ node }}<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { match syntax.kind() { {{ node | SCREAM }} => Some({{ node }} { syntax }), _ => None, } } - fn syntax(&self) -> &SyntaxNode { &self.syntax } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } {% endif %} {% if methods.traits -%} {%- for t in methods.traits -%} -impl ast::{{ t }} for {{ node }} {} +impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {} {% endfor -%} {%- endif -%} -impl {{ node }} { +impl<'a> {{ node }}<'a> { {%- if methods.collections -%} {%- for m in methods.collections -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} - pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator> + 'a { + pub fn {{ method_name }}(self) -> impl Iterator> + 'a { self.syntax() .children() .filter_map({{ ChildName }}::cast) @@ -70,7 +69,7 @@ impl {{ node }} { {%- for m in methods.options -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} - pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { + pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { self.syntax() .children() .filter_map({{ ChildName }}::cast) -- cgit v1.2.3