2018-10-04 22:43:58 +02:00
|
|
|
{# THIS File is not automatically generated:
|
|
|
|
the below applies to the result of this template
|
2018-10-16 20:09:22 +02:00
|
|
|
#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
|
2018-10-04 22:43:58 +02:00
|
|
|
// Do not edit manually
|
|
|
|
|
2018-10-15 23:44:23 +02:00
|
|
|
#![cfg_attr(rustfmt, rustfmt_skip)]
|
|
|
|
|
2018-10-15 19:53:15 +02:00
|
|
|
use crate::{
|
2018-08-11 11:28:59 +02:00
|
|
|
ast,
|
2018-10-31 08:27:53 +01:00
|
|
|
SyntaxNode, SyntaxNodeRef, AstNode,
|
2018-08-09 16:43:39 +02:00
|
|
|
SyntaxKind::*,
|
|
|
|
};
|
2018-08-11 09:11:58 +02:00
|
|
|
{% for node, methods in ast %}
|
2018-08-11 11:28:59 +02:00
|
|
|
// {{ node }}
|
2018-10-31 08:27:53 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct {{ node }}Node(SyntaxNode);
|
|
|
|
|
|
|
|
impl {{ node }}Node {
|
2018-10-31 08:56:31 +01:00
|
|
|
pub fn new(ast: {{ node }}) -> {{ node }}Node {
|
2018-10-31 08:27:53 +01:00
|
|
|
let syntax = ast.syntax().owned();
|
|
|
|
{{ node }}Node(syntax)
|
|
|
|
}
|
|
|
|
pub fn ast(&self) -> {{ node }} {
|
|
|
|
{{ node }}::cast(self.0.borrowed()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- if methods.enum %}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-17 21:00:13 +02:00
|
|
|
pub enum {{ node }}<'a> {
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- for kind in methods.enum %}
|
2018-08-17 21:00:13 +02:00
|
|
|
{{ kind }}({{ kind }}<'a>),
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- endfor %}
|
|
|
|
}
|
|
|
|
|
2018-08-17 21:00:13 +02:00
|
|
|
impl<'a> AstNode<'a> for {{ node }}<'a> {
|
|
|
|
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
2018-08-14 11:38:20 +02:00
|
|
|
match syntax.kind() {
|
|
|
|
{%- for kind in methods.enum %}
|
|
|
|
{{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })),
|
|
|
|
{%- endfor %}
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2018-08-17 21:00:13 +02:00
|
|
|
fn syntax(self) -> SyntaxNodeRef<'a> {
|
2018-08-14 11:38:20 +02:00
|
|
|
match self {
|
|
|
|
{%- for kind in methods.enum %}
|
|
|
|
{{ node }}::{{ kind }}(inner) => inner.syntax(),
|
|
|
|
{%- endfor %}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{% else %}
|
2018-08-10 14:07:43 +02:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-08-17 21:00:13 +02:00
|
|
|
pub struct {{ node }}<'a> {
|
|
|
|
syntax: SyntaxNodeRef<'a>,
|
2018-08-09 16:43:39 +02:00
|
|
|
}
|
|
|
|
|
2018-08-17 21:00:13 +02:00
|
|
|
impl<'a> AstNode<'a> for {{ node }}<'a> {
|
|
|
|
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
2018-08-09 16:43:39 +02:00
|
|
|
match syntax.kind() {
|
2018-08-11 10:03:22 +02:00
|
|
|
{{ node | SCREAM }} => Some({{ node }} { syntax }),
|
2018-08-09 16:43:39 +02:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2018-08-17 21:00:13 +02:00
|
|
|
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
2018-08-09 16:43:39 +02:00
|
|
|
}
|
2018-08-14 11:38:20 +02:00
|
|
|
{% endif %}
|
2018-08-11 11:28:59 +02:00
|
|
|
{% if methods.traits -%}
|
|
|
|
{%- for t in methods.traits -%}
|
2018-08-17 21:00:13 +02:00
|
|
|
impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {}
|
2018-08-11 11:28:59 +02:00
|
|
|
{% endfor -%}
|
|
|
|
{%- endif -%}
|
|
|
|
|
2018-08-17 21:00:13 +02:00
|
|
|
impl<'a> {{ node }}<'a> {
|
2018-08-11 09:11:58 +02:00
|
|
|
{%- if methods.collections -%}
|
|
|
|
{%- for m in methods.collections -%}
|
2018-08-11 08:55:32 +02:00
|
|
|
{%- set method_name = m.0 -%}
|
2018-08-11 09:11:58 +02:00
|
|
|
{%- set ChildName = m.1 %}
|
2018-08-17 21:00:13 +02:00
|
|
|
pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a {
|
2018-08-22 16:01:51 +02:00
|
|
|
super::children(self)
|
2018-08-11 08:38:27 +02:00
|
|
|
}
|
2018-08-11 08:55:32 +02:00
|
|
|
{% endfor -%}
|
|
|
|
{%- endif -%}
|
|
|
|
|
2018-08-11 09:11:58 +02:00
|
|
|
{%- if methods.options -%}
|
|
|
|
{%- for m in methods.options -%}
|
2018-08-31 14:10:37 +02:00
|
|
|
|
|
|
|
{%- if m is string -%}
|
|
|
|
{%- set method_name = m | snake -%}
|
|
|
|
{%- set ChildName = m %}
|
|
|
|
{%- else -%}
|
2018-08-11 08:55:32 +02:00
|
|
|
{%- set method_name = m.0 -%}
|
2018-08-11 09:11:58 +02:00
|
|
|
{%- set ChildName = m.1 %}
|
2018-10-10 17:18:21 +02:00
|
|
|
{%- endif %}
|
2018-08-17 21:00:13 +02:00
|
|
|
pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
|
2018-08-22 16:01:51 +02:00
|
|
|
super::child_opt(self)
|
2018-08-11 08:55:32 +02:00
|
|
|
}
|
|
|
|
{% endfor -%}
|
|
|
|
{%- endif -%}
|
2018-08-11 08:38:27 +02:00
|
|
|
}
|
2018-08-09 16:43:39 +02:00
|
|
|
{% endfor %}
|