From 9fae494a8da347a32cdcd3dcd714ba00aaff9664 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 11:40:17 +0300 Subject: Move ParsedFile to top --- crates/libsyntax2/src/ast/mod.rs | 25 +------------------------ crates/libsyntax2/src/lib.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 25 deletions(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index ba80fc64e..6217c5b74 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs @@ -4,8 +4,7 @@ use itertools::Itertools; use smol_str::SmolStr; use { - SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError, - SyntaxKind::*, + SyntaxNodeRef, SyntaxKind::*, }; pub use self::generated::*; @@ -37,28 +36,6 @@ pub trait AttrsOwner<'a>: AstNode<'a> { } } -#[derive(Clone, Debug)] -pub struct ParsedFile { - root: SyntaxNode -} - -impl ParsedFile { - pub fn parse(text: &str) -> Self { - let root = ::parse(text); - ParsedFile { root } - } - pub fn ast(&self) -> File { - File::cast(self.syntax()).unwrap() - } - pub fn syntax(&self) -> SyntaxNodeRef { - self.root.borrowed() - } - pub fn errors(&self) -> Vec { - self.syntax().root.syntax_root().errors.clone() - } - -} - impl<'a> FnDef<'a> { pub fn has_atom_attr(&self, atom: &str) -> bool { self.attrs() diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index 9f9f3ab3a..b3efe2a18 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -44,12 +44,33 @@ pub mod text_utils; pub use { text_unit::{TextRange, TextUnit}, smol_str::SmolStr, - ast::{AstNode, ParsedFile}, + ast::AstNode, lexer::{tokenize, Token}, syntax_kinds::SyntaxKind, yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, }; +#[derive(Clone, Debug)] +pub struct ParsedFile { + root: SyntaxNode +} + +impl ParsedFile { + pub fn parse(text: &str) -> Self { + let root = ::parse(text); + ParsedFile { root } + } + pub fn ast(&self) -> ast::File { + ast::File::cast(self.syntax()).unwrap() + } + pub fn syntax(&self) -> SyntaxNodeRef { + self.root.borrowed() + } + pub fn errors(&self) -> Vec { + self.syntax().root.syntax_root().errors.clone() + } + +} pub fn parse(text: &str) -> SyntaxNode { let tokens = tokenize(&text); -- cgit v1.2.3