diff options
author | Aleksey Kladov <[email protected]> | 2018-08-25 09:40:17 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-25 09:40:17 +0100 |
commit | 9fae494a8da347a32cdcd3dcd714ba00aaff9664 (patch) | |
tree | 9fe4fb51c374d036e22d5a60ce50b63dbe287142 /crates/libsyntax2/src | |
parent | f104458d45e30024f8a4a02c1ad4101ed74b08f9 (diff) |
Move ParsedFile to top
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 25 | ||||
-rw-r--r-- | crates/libsyntax2/src/lib.rs | 23 |
2 files changed, 23 insertions, 25 deletions
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; | |||
4 | use smol_str::SmolStr; | 4 | use smol_str::SmolStr; |
5 | 5 | ||
6 | use { | 6 | use { |
7 | SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError, | 7 | SyntaxNodeRef, SyntaxKind::*, |
8 | SyntaxKind::*, | ||
9 | }; | 8 | }; |
10 | pub use self::generated::*; | 9 | pub use self::generated::*; |
11 | 10 | ||
@@ -37,28 +36,6 @@ pub trait AttrsOwner<'a>: AstNode<'a> { | |||
37 | } | 36 | } |
38 | } | 37 | } |
39 | 38 | ||
40 | #[derive(Clone, Debug)] | ||
41 | pub struct ParsedFile { | ||
42 | root: SyntaxNode | ||
43 | } | ||
44 | |||
45 | impl ParsedFile { | ||
46 | pub fn parse(text: &str) -> Self { | ||
47 | let root = ::parse(text); | ||
48 | ParsedFile { root } | ||
49 | } | ||
50 | pub fn ast(&self) -> File { | ||
51 | File::cast(self.syntax()).unwrap() | ||
52 | } | ||
53 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
54 | self.root.borrowed() | ||
55 | } | ||
56 | pub fn errors(&self) -> Vec<SyntaxError> { | ||
57 | self.syntax().root.syntax_root().errors.clone() | ||
58 | } | ||
59 | |||
60 | } | ||
61 | |||
62 | impl<'a> FnDef<'a> { | 39 | impl<'a> FnDef<'a> { |
63 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 40 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
64 | self.attrs() | 41 | 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; | |||
44 | pub use { | 44 | pub use { |
45 | text_unit::{TextRange, TextUnit}, | 45 | text_unit::{TextRange, TextUnit}, |
46 | smol_str::SmolStr, | 46 | smol_str::SmolStr, |
47 | ast::{AstNode, ParsedFile}, | 47 | ast::AstNode, |
48 | lexer::{tokenize, Token}, | 48 | lexer::{tokenize, Token}, |
49 | syntax_kinds::SyntaxKind, | 49 | syntax_kinds::SyntaxKind, |
50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, | 50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #[derive(Clone, Debug)] | ||
54 | pub struct ParsedFile { | ||
55 | root: SyntaxNode | ||
56 | } | ||
57 | |||
58 | impl ParsedFile { | ||
59 | pub fn parse(text: &str) -> Self { | ||
60 | let root = ::parse(text); | ||
61 | ParsedFile { root } | ||
62 | } | ||
63 | pub fn ast(&self) -> ast::File { | ||
64 | ast::File::cast(self.syntax()).unwrap() | ||
65 | } | ||
66 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
67 | self.root.borrowed() | ||
68 | } | ||
69 | pub fn errors(&self) -> Vec<SyntaxError> { | ||
70 | self.syntax().root.syntax_root().errors.clone() | ||
71 | } | ||
72 | |||
73 | } | ||
53 | 74 | ||
54 | pub fn parse(text: &str) -> SyntaxNode { | 75 | pub fn parse(text: &str) -> SyntaxNode { |
55 | let tokens = tokenize(&text); | 76 | let tokens = tokenize(&text); |