rust/crates/libsyntax2/src/ast/generated.rs.tera

57 lines
1.4 KiB
Text
Raw Normal View History

2018-08-09 16:43:39 +02:00
use std::sync::Arc;
use {
2018-08-11 11:28:59 +02:00
ast,
2018-08-09 16:43:39 +02:00
SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
SyntaxKind::*,
};
2018-08-11 09:11:58 +02:00
{% for node, methods in ast %}
2018-08-11 11:28:59 +02:00
// {{ node }}
2018-08-10 14:07:43 +02:00
#[derive(Debug, Clone, Copy)]
2018-08-11 09:11:58 +02:00
pub struct {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> {
2018-08-09 16:43:39 +02:00
syntax: SyntaxNode<R>,
}
2018-08-11 09:11:58 +02:00
impl<R: TreeRoot> AstNode<R> for {{ node }}<R> {
2018-08-09 16:43:39 +02:00
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
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,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
2018-08-11 08:38:27 +02:00
2018-08-11 11:28:59 +02:00
{% if methods.traits -%}
{%- for t in methods.traits -%}
impl<R: TreeRoot> ast::{{ t }}<R> for {{ node }}<R> {}
{% endfor -%}
{%- endif -%}
2018-08-11 09:11:58 +02:00
impl<R: TreeRoot> {{ node }}<R> {
{%- 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-11 08:55:32 +02:00
pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildName }}<R>> + 'a {
2018-08-11 08:38:27 +02:00
self.syntax()
.children()
2018-08-11 08:55:32 +02:00
.filter_map({{ ChildName }}::cast)
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-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-11 08:55:32 +02:00
pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}<R>> {
self.syntax()
.children()
.filter_map({{ ChildName }}::cast)
.next()
}
{% endfor -%}
{%- endif -%}
2018-08-11 08:38:27 +02:00
}
2018-08-09 16:43:39 +02:00
{% endfor %}