blob: afce068c867d5acbdcd7cb43ad6c8a32487a2e7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use std::sync::Arc;
use {
SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
SyntaxKind::*,
};
{% for node in ast %}
{% set Name = node.kind | camel %}
#[derive(Debug, Clone, Copy)]
pub struct {{ Name }}<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for {{ Name }}<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
{{ node.kind }} => Some({{ Name }} { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> {{ Name }}<R> {
{% for (method_name, kind) in node.opts %}
{% set ChildName = kind | camel %}
pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildKind }}<R>> + 'a {
self.syntax()
.children()
.filter_map({{ ChildKind }}::cast)
}
{% endfor %}
}
{% endfor %}
|