diff options
author | Aleksey Kladov <[email protected]> | 2019-07-21 11:34:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-21 11:34:15 +0100 |
commit | 773ad2edb3b84bf20378a577bc4cd808384de078 (patch) | |
tree | 867145208375ea242078f6a3e3237d8fb76c5be9 /crates/ra_syntax/src/lib.rs | |
parent | d52ee59a712932bc381d8c690dc2f681598760fe (diff) |
simiplify
Diffstat (limited to 'crates/ra_syntax/src/lib.rs')
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index d02078256..7f69b86e1 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -143,18 +143,17 @@ impl Parse<SourceFile> { | |||
143 | pub use crate::ast::SourceFile; | 143 | pub use crate::ast::SourceFile; |
144 | 144 | ||
145 | impl SourceFile { | 145 | impl SourceFile { |
146 | fn new(green: GreenNode) -> SourceFile { | 146 | pub fn parse(text: &str) -> Parse<SourceFile> { |
147 | let root = SyntaxNode::new_root(green); | 147 | let (green, mut errors) = parsing::parse_text(text); |
148 | let root = SyntaxNode::new_root(green.clone()); | ||
149 | |||
148 | if cfg!(debug_assertions) { | 150 | if cfg!(debug_assertions) { |
149 | validation::validate_block_structure(&root); | 151 | validation::validate_block_structure(&root); |
150 | } | 152 | } |
151 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); | ||
152 | SourceFile::cast(root).unwrap() | ||
153 | } | ||
154 | 153 | ||
155 | pub fn parse(text: &str) -> Parse<SourceFile> { | 154 | errors.extend(validation::validate(&root)); |
156 | let (green, mut errors) = parsing::parse_text(text); | 155 | |
157 | errors.extend(validation::validate(&SourceFile::new(green.clone()))); | 156 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); |
158 | Parse { green, errors: Arc::new(errors), _ty: PhantomData } | 157 | Parse { green, errors: Arc::new(errors), _ty: PhantomData } |
159 | } | 158 | } |
160 | } | 159 | } |