aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-25 09:40:17 +0100
committerAleksey Kladov <[email protected]>2018-08-25 09:40:17 +0100
commit9fae494a8da347a32cdcd3dcd714ba00aaff9664 (patch)
tree9fe4fb51c374d036e22d5a60ce50b63dbe287142 /crates/libsyntax2/src
parentf104458d45e30024f8a4a02c1ad4101ed74b08f9 (diff)
Move ParsedFile to top
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/mod.rs25
-rw-r--r--crates/libsyntax2/src/lib.rs23
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;
4use smol_str::SmolStr; 4use smol_str::SmolStr;
5 5
6use { 6use {
7 SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError, 7 SyntaxNodeRef, SyntaxKind::*,
8 SyntaxKind::*,
9}; 8};
10pub use self::generated::*; 9pub 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)]
41pub struct ParsedFile {
42 root: SyntaxNode
43}
44
45impl 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
62impl<'a> FnDef<'a> { 39impl<'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;
44pub use { 44pub 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)]
54pub struct ParsedFile {
55 root: SyntaxNode
56}
57
58impl 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
54pub fn parse(text: &str) -> SyntaxNode { 75pub fn parse(text: &str) -> SyntaxNode {
55 let tokens = tokenize(&text); 76 let tokens = tokenize(&text);