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

49 lines
1.2 KiB
Text
Raw Normal View History

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