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-11-06 20:06:58 +01:00
|
|
|
//! 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.
|
|
|
|
|
2018-10-15 23:44:23 +02:00
|
|
|
#![cfg_attr(rustfmt, rustfmt_skip)]
|
|
|
|
|
2019-01-07 14:15:47 +01:00
|
|
|
use rowan::TransparentNewType;
|
2018-11-06 20:47:38 +01:00
|
|
|
|
2018-10-15 19:53:15 +02:00
|
|
|
use crate::{
|
2019-01-07 14:15:47 +01:00
|
|
|
SyntaxNode, SyntaxKind::*,
|
|
|
|
yellow::{RaTypes, TreePtr},
|
|
|
|
ast::{self, AstNode},
|
2018-08-09 16:43:39 +02:00
|
|
|
};
|
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
|
|
|
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- if methods.enum %}
|
2019-01-07 14:15:47 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct {{ node }} {
|
|
|
|
pub(crate) syntax: SyntaxNode,
|
|
|
|
}
|
|
|
|
unsafe impl TransparentNewType for {{ node }} {
|
|
|
|
type Repr = rowan::SyntaxNode<RaTypes>;
|
|
|
|
}
|
|
|
|
|
2018-11-06 20:47:38 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
2019-01-07 14:15:47 +01:00
|
|
|
pub enum {{ node }}Kind<'a> {
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- for kind in methods.enum %}
|
2019-01-07 14:15:47 +01:00
|
|
|
{{ kind }}(&'a {{ kind }}),
|
2018-08-14 11:38:20 +02:00
|
|
|
{%- endfor %}
|
|
|
|
}
|
|
|
|
|
2019-01-07 14:15:47 +01:00
|
|
|
impl AstNode for {{ node }} {
|
|
|
|
fn cast(syntax: &SyntaxNode) -> Option<&Self> {
|
2018-08-14 11:38:20 +02:00
|
|
|
match syntax.kind() {
|
2019-01-07 14:15:47 +01:00
|
|
|
{%- for kind in methods.enum %}
|
|
|
|
| {{ kind | SCREAM }}
|
|
|
|
{%- endfor %} => Some({{ node }}::from_repr(syntax.into_repr())),
|
2018-08-14 11:38:20 +02:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 14:15:47 +01:00
|
|
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
|
|
|
fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
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).unwrap()),
|
|
|
|
{%- endfor %}
|
|
|
|
_ => unreachable!(),
|
2018-08-14 11:38:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{% else %}
|
2019-01-07 14:15:47 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct {{ node }} {
|
|
|
|
pub(crate) syntax: SyntaxNode,
|
2018-08-09 16:43:39 +02:00
|
|
|
}
|
2019-01-07 14:15:47 +01:00
|
|
|
unsafe impl TransparentNewType for {{ node }} {
|
|
|
|
type Repr = rowan::SyntaxNode<RaTypes>;
|
2018-11-06 20:47:38 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 14:15:47 +01:00
|
|
|
impl AstNode for {{ node }} {
|
|
|
|
fn cast(syntax: &SyntaxNode) -> Option<&Self> {
|
2018-08-09 16:43:39 +02:00
|
|
|
match syntax.kind() {
|
2019-01-07 14:15:47 +01:00
|
|
|
{{ node | SCREAM }} => Some({{ node }}::from_repr(syntax.into_repr())),
|
2018-08-09 16:43:39 +02:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 14:15:47 +01:00
|
|
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
|
|
|
fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) }
|
2018-11-06 19:52:00 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 11:38:20 +02:00
|
|
|
{% endif %}
|
2018-08-11 11:28:59 +02:00
|
|
|
{% if methods.traits -%}
|
2019-01-07 14:15:47 +01:00
|
|
|
|
2018-08-11 11:28:59 +02:00
|
|
|
{%- for t in methods.traits -%}
|
2019-01-07 14:15:47 +01:00
|
|
|
impl ast::{{ t }} for {{ node }} {}
|
2018-08-11 11:28:59 +02:00
|
|
|
{% endfor -%}
|
2019-01-07 14:15:47 +01:00
|
|
|
|
2018-08-11 11:28:59 +02:00
|
|
|
{%- endif -%}
|
|
|
|
|
2019-01-07 14:15:47 +01:00
|
|
|
impl {{ node }} {
|
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 %}
|
2019-01-07 14:15:47 +01:00
|
|
|
pub fn {{ method_name }}(&self) -> impl Iterator<Item = &{{ ChildName }}> {
|
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 %}
|
2019-01-07 14:15:47 +01:00
|
|
|
pub fn {{ method_name }}(&self) -> Option<&{{ ChildName }}> {
|
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 %}
|