mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
rename all things
This commit is contained in:
parent
ba0bfeee12
commit
b5021411a8
478 changed files with 219 additions and 204 deletions
83
crates/ra_syntax/src/ast/generated.rs.tera
Normal file
83
crates/ra_syntax/src/ast/generated.rs.tera
Normal file
|
@ -0,0 +1,83 @@
|
|||
use {
|
||||
ast,
|
||||
SyntaxNodeRef, AstNode,
|
||||
SyntaxKind::*,
|
||||
};
|
||||
{% for node, methods in ast %}
|
||||
// {{ node }}
|
||||
{%- if methods.enum %}
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum {{ node }}<'a> {
|
||||
{%- for kind in methods.enum %}
|
||||
{{ kind }}({{ kind }}<'a>),
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for {{ node }}<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
{%- for kind in methods.enum %}
|
||||
{{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })),
|
||||
{%- endfor %}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> {
|
||||
match self {
|
||||
{%- for kind in methods.enum %}
|
||||
{{ node }}::{{ kind }}(inner) => inner.syntax(),
|
||||
{%- endfor %}
|
||||
}
|
||||
}
|
||||
}
|
||||
{% else %}
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct {{ node }}<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for {{ node }}<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
{{ node | SCREAM }} => Some({{ node }} { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
{% endif %}
|
||||
{% if methods.traits -%}
|
||||
{%- for t in methods.traits -%}
|
||||
impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {}
|
||||
{% endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
impl<'a> {{ node }}<'a> {
|
||||
{%- if methods.collections -%}
|
||||
{%- for m in methods.collections -%}
|
||||
{%- set method_name = m.0 -%}
|
||||
{%- set ChildName = m.1 %}
|
||||
pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
{% endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if methods.options -%}
|
||||
{%- for m in methods.options -%}
|
||||
|
||||
{%- if m is string -%}
|
||||
{%- set method_name = m | snake -%}
|
||||
{%- set ChildName = m %}
|
||||
{%- else -%}
|
||||
{%- set method_name = m.0 -%}
|
||||
{%- set ChildName = m.1 %}
|
||||
{%- endif -%}
|
||||
|
||||
pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
{% endfor -%}
|
||||
{%- endif -%}
|
||||
}
|
||||
{% endfor %}
|
Loading…
Add table
Add a link
Reference in a new issue