rust-analyzer/crates/ra_syntax/src/ast/generated.rs.tera

119 lines
3.4 KiB
Text
Raw Normal View History

2018-10-04 20:43:58 +00:00
{# THIS File is not automatically generated:
the below applies to the result of this template
2018-10-16 18:09:22 +00:00
#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
2018-10-04 20:43:58 +00:00
// Do not edit manually
2018-11-06 19:06:58 +00: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.
#![cfg_attr(rustfmt, rustfmt_skip)]
2018-11-06 19:47:38 +00:00
use std::hash::{Hash, Hasher};
2018-10-15 17:53:15 +00:00
use crate::{
2018-08-11 09:28:59 +00:00
ast,
SyntaxNode, SyntaxNodeRef, AstNode,
2018-11-06 18:52:00 +00:00
yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot},
2018-08-09 14:43:39 +00:00
SyntaxKind::*,
};
2018-08-11 07:11:58 +00:00
{% for node, methods in ast %}
2018-08-11 09:28:59 +00:00
// {{ node }}
2018-08-14 09:38:20 +00:00
{%- if methods.enum %}
2018-11-06 19:47:38 +00:00
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2018-08-17 19:00:13 +00:00
pub enum {{ node }}<'a> {
2018-08-14 09:38:20 +00:00
{%- for kind in methods.enum %}
2018-08-17 19:00:13 +00:00
{{ kind }}({{ kind }}<'a>),
2018-08-14 09:38:20 +00:00
{%- endfor %}
}
2018-08-17 19:00:13 +00:00
impl<'a> AstNode<'a> for {{ node }}<'a> {
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2018-08-14 09:38:20 +00:00
match syntax.kind() {
{%- for kind in methods.enum %}
{{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })),
{%- endfor %}
_ => None,
}
}
2018-08-17 19:00:13 +00:00
fn syntax(self) -> SyntaxNodeRef<'a> {
2018-08-14 09:38:20 +00:00
match self {
{%- for kind in methods.enum %}
{{ node }}::{{ kind }}(inner) => inner.syntax(),
{%- endfor %}
}
}
}
{% else %}
2018-11-06 19:47:38 +00:00
#[derive(Debug, Clone, Copy,)]
2018-11-06 18:52:00 +00:00
pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> {
2018-11-06 19:47:38 +00:00
pub(crate) syntax: SyntaxNode<R>,
2018-08-09 14:43:39 +00:00
}
2018-11-06 18:52:00 +00:00
pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>;
2018-08-09 14:43:39 +00:00
2018-11-06 19:47:38 +00:00
impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<{{node}}Node<R1>> for {{node}}Node<R2> {
fn eq(&self, other: &{{node}}Node<R1>) -> bool { self.syntax == other.syntax }
}
impl<R: TreeRoot<RaTypes>> Eq for {{node}}Node<R> {}
impl<R: TreeRoot<RaTypes>> Hash for {{node}}Node<R> {
fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
}
2018-08-17 19:00:13 +00:00
impl<'a> AstNode<'a> for {{ node }}<'a> {
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
2018-08-09 14:43:39 +00:00
match syntax.kind() {
2018-08-11 08:03:22 +00:00
{{ node | SCREAM }} => Some({{ node }} { syntax }),
2018-08-09 14:43:39 +00:00
_ => None,
}
}
2018-08-17 19:00:13 +00:00
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2018-08-09 14:43:39 +00:00
}
2018-11-06 18:52:00 +00:00
impl<R: TreeRoot<RaTypes>> {{ node }}Node<R> {
pub fn borrowed(&self) -> {{ node }} {
{{ node }}Node { syntax: self.syntax.borrowed() }
}
pub fn owned(&self) -> {{ node }}Node {
{{ node }}Node { syntax: self.syntax.owned() }
}
}
2018-08-14 09:38:20 +00:00
{% endif %}
2018-08-11 09:28:59 +00:00
{% if methods.traits -%}
{%- for t in methods.traits -%}
2018-08-17 19:00:13 +00:00
impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {}
2018-08-11 09:28:59 +00:00
{% endfor -%}
{%- endif -%}
2018-08-17 19:00:13 +00:00
impl<'a> {{ node }}<'a> {
2018-08-11 07:11:58 +00:00
{%- if methods.collections -%}
{%- for m in methods.collections -%}
2018-08-11 06:55:32 +00:00
{%- set method_name = m.0 -%}
2018-08-11 07:11:58 +00:00
{%- set ChildName = m.1 %}
2018-08-17 19:00:13 +00:00
pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a {
2018-08-22 14:01:51 +00:00
super::children(self)
2018-08-11 06:38:27 +00:00
}
2018-08-11 06:55:32 +00:00
{% endfor -%}
{%- endif -%}
2018-08-11 07:11:58 +00:00
{%- if methods.options -%}
{%- for m in methods.options -%}
2018-08-31 12:10:37 +00:00
{%- if m is string -%}
{%- set method_name = m | snake -%}
{%- set ChildName = m %}
{%- else -%}
2018-08-11 06:55:32 +00:00
{%- set method_name = m.0 -%}
2018-08-11 07:11:58 +00:00
{%- set ChildName = m.1 %}
{%- endif %}
2018-08-17 19:00:13 +00:00
pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
2018-08-22 14:01:51 +00:00
super::child_opt(self)
2018-08-11 06:55:32 +00:00
}
{% endfor -%}
{%- endif -%}
2018-08-11 06:38:27 +00:00
}
2018-08-09 14:43:39 +00:00
{% endfor %}