From 773ad2edb3b84bf20378a577bc4cd808384de078 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 21 Jul 2019 13:34:15 +0300 Subject: simiplify --- crates/ra_syntax/src/lib.rs | 15 +++++++-------- crates/ra_syntax/src/validation.rs | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'crates') 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 { pub use crate::ast::SourceFile; impl SourceFile { - fn new(green: GreenNode) -> SourceFile { - let root = SyntaxNode::new_root(green); + pub fn parse(text: &str) -> Parse { + let (green, mut errors) = parsing::parse_text(text); + let root = SyntaxNode::new_root(green.clone()); + if cfg!(debug_assertions) { validation::validate_block_structure(&root); } - assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); - SourceFile::cast(root).unwrap() - } - pub fn parse(text: &str) -> Parse { - let (green, mut errors) = parsing::parse_text(text); - errors.extend(validation::validate(&SourceFile::new(green.clone()))); + errors.extend(validation::validate(&root)); + + assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); Parse { green, errors: Arc::new(errors), _ty: PhantomData } } } 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; use crate::{ algo::visit::{visitor_ctx, VisitorCtx}, - ast, AstNode, SourceFile, SyntaxError, + ast, SyntaxError, SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING}, SyntaxNode, TextUnit, T, }; pub(crate) use unescape::EscapeError; -pub(crate) fn validate(file: &SourceFile) -> Vec { +pub(crate) fn validate(root: &SyntaxNode) -> Vec { let mut errors = Vec::new(); - for node in file.syntax().descendants() { + for node in root.descendants() { let _ = visitor_ctx(&mut errors) .visit::(validate_literal) .visit::(block::validate_block_node) -- cgit v1.2.3