This commit is contained in:
Aleksey Kladov 2018-08-11 12:28:59 +03:00
parent d5119133fc
commit 7afd84febc
11 changed files with 211 additions and 86 deletions

View file

@ -12,6 +12,15 @@ pub trait AstNode<R: TreeRoot>: Sized {
fn syntax(&self) -> &SyntaxNode<R>;
}
pub trait NameOwner<R: TreeRoot>: AstNode<R> {
fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}
impl File<Arc<SyntaxRoot>> {
pub fn parse(text: &str) -> Self {
File::cast(::parse(text)).unwrap()