aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/lib.rs15
-rw-r--r--crates/ra_syntax/src/validation.rs6
2 files changed, 10 insertions, 11 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> {
143pub use crate::ast::SourceFile; 143pub use crate::ast::SourceFile;
144 144
145impl SourceFile { 145impl 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}
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index 19bdafef2..e03c02d1b 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -5,16 +5,16 @@ mod field_expr;
5 5
6use crate::{ 6use crate::{
7 algo::visit::{visitor_ctx, VisitorCtx}, 7 algo::visit::{visitor_ctx, VisitorCtx},
8 ast, AstNode, SourceFile, SyntaxError, 8 ast, SyntaxError,
9 SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING}, 9 SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING},
10 SyntaxNode, TextUnit, T, 10 SyntaxNode, TextUnit, T,
11}; 11};
12 12
13pub(crate) use unescape::EscapeError; 13pub(crate) use unescape::EscapeError;
14 14
15pub(crate) fn validate(file: &SourceFile) -> Vec<SyntaxError> { 15pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
16 let mut errors = Vec::new(); 16 let mut errors = Vec::new();
17 for node in file.syntax().descendants() { 17 for node in root.descendants() {
18 let _ = visitor_ctx(&mut errors) 18 let _ = visitor_ctx(&mut errors)
19 .visit::<ast::Literal, _>(validate_literal) 19 .visit::<ast::Literal, _>(validate_literal)
20 .visit::<ast::Block, _>(block::validate_block_node) 20 .visit::<ast::Block, _>(block::validate_block_node)