{# THIS File is not automatically generated: the below applies to the result of this template #}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run // Do not edit manually //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode` //! are Arc-based. You can switch between the two variants using `.owned` and //! `.borrowed` functions. Most of the code works with borowed mode, and only //! this mode has all AST accessors. #![cfg_attr(rustfmt, rustfmt_skip)] use crate::{ SyntaxNode, SyntaxKind::*, ast::{self, AstNode}, }; {% for node, methods in ast %} // {{ node }} {%- if methods.enum %} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct {{ node }} { pub(crate) syntax: SyntaxNode, } #[derive(Debug, Clone, PartialEq, Eq)] pub enum {{ node }}Kind { {%- for kind in methods.enum %} {{ kind }}({{ kind }}), {%- endfor %} } {%- for kind in methods.enum %} impl From<{{ kind }}> for {{ node }} { fn from(n: {{ kind }}) -> {{ node }} { {{ node }}::cast(n.syntax).unwrap() } } {%- endfor %} impl AstNode for {{ node }} { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { {%- for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor %} => Some({{ node }} { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl {{ node }} { pub fn kind(&self) -> {{ node }}Kind { match self.syntax.kind() { {%- for kind in methods.enum %} {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()), {%- endfor %} _ => unreachable!(), } } } {% else %} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct {{ node }} { pub(crate) syntax: SyntaxNode, } impl AstNode for {{ node }} { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { {{ node | SCREAM }} => Some({{ node }} { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } {% endif %} {% if methods.traits -%} {%- for t in methods.traits -%} impl ast::{{ t }} for {{ node }} {} {% endfor -%} {%- endif -%} impl {{ node }} { {%- if methods.collections -%} {%- for m in methods.collections -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} pub fn {{ method_name }}(&self) -> impl Iterator { super::children(self) } {% endfor -%} {%- endif -%} {%- if methods.options -%} {%- for m in methods.options -%} {%- if m is string -%} {%- set method_name = m | snake -%} {%- set ChildName = m %} {%- else -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} {%- endif %} pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { super::child_opt(self) } {% endfor -%} {%- endif -%} } {% endfor %}