rust/src/ast/generated.rs

55 lines
1.2 KiB
Rust
Raw Normal View History

2018-08-09 16:43:39 +02:00
use std::sync::Arc;
use {
SyntaxNode, SyntaxRoot, TreeRoot, AstNode,
SyntaxKind::*,
};
#[derive(Debug)]
pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for File<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
FILE => Some(File { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
#[derive(Debug)]
2018-08-09 16:44:40 +02:00
pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> {
2018-08-09 16:43:39 +02:00
syntax: SyntaxNode<R>,
}
2018-08-09 16:44:40 +02:00
impl<R: TreeRoot> AstNode<R> for Function<R> {
2018-08-09 16:43:39 +02:00
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
2018-08-09 16:44:40 +02:00
FUNCTION => Some(Function { syntax }),
2018-08-09 16:43:39 +02:00
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
#[derive(Debug)]
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() {
NAME => Some(Name { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}