From d8b2a5efc0e5de3b0d72f29ccc86185f0827c9d3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Aug 2018 17:43:39 +0300 Subject: Generate AST --- src/ast.rs | 94 -------------------------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 src/ast.rs (limited to 'src/ast.rs') diff --git a/src/ast.rs b/src/ast.rs deleted file mode 100644 index a595b9324..000000000 --- a/src/ast.rs +++ /dev/null @@ -1,94 +0,0 @@ -use std::sync::Arc; -use { - SyntaxNode, SyntaxRoot, TreeRoot, - SyntaxKind::*, -}; - -#[derive(Debug)] -pub struct File> { - syntax: SyntaxNode, -} - -#[derive(Debug)] -pub struct Function> { - syntax: SyntaxNode, -} - -#[derive(Debug)] -pub struct Name> { - syntax: SyntaxNode, -} - - -impl File> { - pub fn parse(text: &str) -> Self { - File { - syntax: ::parse(text), - } - } -} - -impl File { - pub fn functions<'a>(&'a self) -> impl Iterator> + 'a { - self.syntax - .children() - .filter(|node| node.kind() == FN_ITEM) - .map(|node| Function { syntax: node }) - } -} - -impl Function { - pub fn syntax(&self) -> SyntaxNode { - self.syntax.clone() - } - - pub fn name(&self) -> Option> { - self.syntax - .children() - .filter(|node| node.kind() == NAME) - .map(|node| Name { syntax: node }) - .next() - } - - pub fn has_atom_attr(&self, atom: &str) -> bool { - self.syntax - .children() - .filter(|node| node.kind() == ATTR) - .any(|attr| { - let mut metas = attr.children().filter(|node| node.kind() == META_ITEM); - let meta = match metas.next() { - None => return false, - Some(meta) => { - if metas.next().is_some() { - return false; - } - meta - } - }; - let mut children = meta.children(); - match children.next() { - None => false, - Some(child) => { - if children.next().is_some() { - return false; - } - child.kind() == IDENT && child.text() == atom - } - } - }) - } -} - -impl Name { - pub fn text(&self) -> String { - self.syntax.text() - } -} - - - -impl File { - pub fn syntax(&self) -> SyntaxNode { - self.syntax.clone() - } -} -- cgit v1.2.3