diff options
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 | } |