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

34 lines
892 B
Text
Raw Normal View History

2018-08-09 14:43:39 +00:00
use std::sync::Arc;
use {
SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
SyntaxKind::*,
};
{% for node in ast %}
{% set Name = node.kind | camel %}
2018-08-10 12:07:43 +00:00
#[derive(Debug, Clone, Copy)]
2018-08-09 14:43:39 +00:00
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 }
}
2018-08-11 06:38:27 +00:00
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 %}
}
2018-08-09 14:43:39 +00:00
{% endfor %}