ra_syntax::File is just RootNode

This commit is contained in:
Aleksey Kladov 2018-11-06 22:47:38 +03:00
parent 7196286ec5
commit 8eaf7952ae
4 changed files with 969 additions and 206 deletions

View file

@ -11,6 +11,8 @@ the below applies to the result of this template
#![cfg_attr(rustfmt, rustfmt_skip)]
use std::hash::{Hash, Hasher};
use crate::{
ast,
SyntaxNode, SyntaxNodeRef, AstNode,
@ -21,7 +23,7 @@ use crate::{
// {{ node }}
{%- if methods.enum %}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum {{ node }}<'a> {
{%- for kind in methods.enum %}
{{ kind }}({{ kind }}<'a>),
@ -46,12 +48,20 @@ impl<'a> AstNode<'a> for {{ node }}<'a> {
}
}
{% else %}
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy,)]
pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> {
syntax: SyntaxNode<R>,
pub(crate) syntax: SyntaxNode<R>,
}
pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>;
impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<{{node}}Node<R1>> for {{node}}Node<R2> {
fn eq(&self, other: &{{node}}Node<R1>) -> bool { self.syntax == other.syntax }
}
impl<R: TreeRoot<RaTypes>> Eq for {{node}}Node<R> {}
impl<R: TreeRoot<RaTypes>> Hash for {{node}}Node<R> {
fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
}
impl<'a> AstNode<'a> for {{ node }}<'a> {
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
match syntax.kind() {