aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-06 20:28:04 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-06 20:28:04 +0000
commited1feb72dc8ca8521a3258b0fad3b4ee446f418b (patch)
tree263aed65ed9a8aa30b37674d01f8a82aee66d2f1 /crates/ra_syntax/src/lib.rs
parent7196286ec5de7a545654ca94878230fc31d4a8db (diff)
parent8eaf7952ae4ba510d448a7e310a3e2dcfd09f6d3 (diff)
Merge #211
211: ra_syntax::File is just RootNode r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/lib.rs')
-rw-r--r--crates/ra_syntax/src/lib.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 123002825..aa172ba42 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -60,11 +60,9 @@ pub use crate::{
60 60
61use crate::yellow::GreenNode; 61use crate::yellow::GreenNode;
62 62
63// TODO: pick a single name for everything. SourceFile maybe?
63/// File represents a parse tree for a single Rust file. 64/// File represents a parse tree for a single Rust file.
64#[derive(Clone, Debug, Hash, PartialEq, Eq)] 65pub type File = ast::RootNode;
65pub struct File {
66 root: SyntaxNode,
67}
68 66
69impl File { 67impl File {
70 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File { 68 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File {
@@ -72,7 +70,8 @@ impl File {
72 if cfg!(debug_assertions) { 70 if cfg!(debug_assertions) {
73 utils::validate_block_structure(root.borrowed()); 71 utils::validate_block_structure(root.borrowed());
74 } 72 }
75 File { root } 73 assert_eq!(root.kind(), SyntaxKind::ROOT);
74 ast::RootNode { syntax: root }
76 } 75 }
77 pub fn parse(text: &str) -> File { 76 pub fn parse(text: &str) -> File {
78 let tokens = tokenize(&text); 77 let tokens = tokenize(&text);
@@ -95,14 +94,14 @@ impl File {
95 } 94 }
96 /// Typed AST representation of the parse tree. 95 /// Typed AST representation of the parse tree.
97 pub fn ast(&self) -> ast::Root { 96 pub fn ast(&self) -> ast::Root {
98 ast::Root::cast(self.syntax()).unwrap() 97 self.borrowed()
99 } 98 }
100 /// Untyped homogeneous representation of the parse tree. 99 /// Untyped homogeneous representation of the parse tree.
101 pub fn syntax(&self) -> SyntaxNodeRef { 100 pub fn syntax(&self) -> SyntaxNodeRef {
102 self.root.borrowed() 101 self.syntax.borrowed()
103 } 102 }
104 pub fn errors(&self) -> Vec<SyntaxError> { 103 pub fn errors(&self) -> Vec<SyntaxError> {
105 let mut errors = self.root.root_data().clone(); 104 let mut errors = self.syntax.root_data().clone();
106 errors.extend(validation::validate(self)); 105 errors.extend(validation::validate(self));
107 errors 106 errors
108 } 107 }