From 0efbcdf43544af471a935c790ae99e2a9b5516c3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 17:34:28 +0300 Subject: remove old parsing methods --- crates/ra_syntax/src/lib.rs | 55 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'crates/ra_syntax/src/lib.rs') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 6574eeed1..930a643b7 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -69,6 +69,10 @@ impl Parse { } } + pub fn reparse(&self, edit: &AtomTextEdit) -> Parse { + self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) + } + pub fn debug_dump(&self) -> String { let mut buf = self.tree.syntax().debug_dump(); for err in self.errors.iter() { @@ -76,6 +80,21 @@ impl Parse { } buf } + + fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option { + // FIXME: validation errors are not handled here + parsing::incremental_reparse(self.tree.syntax(), edit, self.errors.to_vec()).map( + |(green_node, errors, _reparsed_range)| Parse { + tree: SourceFile::new(green_node), + errors: Arc::new(errors), + }, + ) + } + + fn full_reparse(&self, edit: &AtomTextEdit) -> Parse { + let text = edit.apply(self.tree.syntax().text().to_string()); + SourceFile::parse(&text) + } } /// `SourceFile` represents a parse tree for a single Rust file. @@ -91,37 +110,12 @@ impl SourceFile { TreeArc::cast(root) } - pub fn parse2(text: &str) -> Parse { + pub fn parse(text: &str) -> Parse { let (green, mut errors) = parsing::parse_text(text); let tree = SourceFile::new(green); errors.extend(validation::validate(&tree)); Parse { tree, errors: Arc::new(errors) } } - - pub fn parse(text: &str) -> TreeArc { - let (green, _errors) = parsing::parse_text(text); - SourceFile::new(green) - } - - pub fn reparse(&self, edit: &AtomTextEdit) -> TreeArc { - self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) - } - - pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option> { - parsing::incremental_reparse(self.syntax(), edit, self.errors()) - .map(|(green_node, _errors, _reparsed_range)| SourceFile::new(green_node)) - } - - fn full_reparse(&self, edit: &AtomTextEdit) -> TreeArc { - let text = edit.apply(self.syntax().text().to_string()); - SourceFile::parse(&text) - } - - pub fn errors(&self) -> Vec { - let mut errors = self.syntax.root_data().to_vec(); - errors.extend(validation::validate(self)); - errors - } } /// This test does not assert anything and instead just shows off the crate's @@ -137,14 +131,15 @@ fn api_walkthrough() { "; // `SourceFile` is the main entry point. // - // Note how `parse` does not return a `Result`: even completely invalid - // source code might be parsed. - let file = SourceFile::parse(source_code); + // The `parse` method returns a `Parse` -- a pair of syntax tree and a list + // of errors. That is, syntax tree is constructed even in presence of errors. + let parse = SourceFile::parse(source_code); + assert!(parse.errors.is_empty()); // Due to the way ownership is set up, owned syntax Nodes always live behind // a `TreeArc` smart pointer. `TreeArc` is roughly an `std::sync::Arc` which // points to the whole file instead of an individual node. - let file: TreeArc = file; + let file: TreeArc = parse.tree; // `SourceFile` is the root of the syntax tree. We can iterate file's items: let mut func = None; -- cgit v1.2.3