From f52eda675e271675c99bb27ed8622690cebb5678 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 May 2019 11:31:27 +0300 Subject: add Parse --- crates/ra_syntax/src/lib.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 0ceabc203..a950870bd 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -31,6 +31,12 @@ pub mod ast; #[doc(hidden)] pub mod fuzz; +use std::sync::Arc; + +use ra_text_edit::AtomTextEdit; + +use crate::syntax_node::GreenNode; + pub use rowan::{SmolStr, TextRange, TextUnit}; pub use ra_parser::SyntaxKind; pub use ra_parser::T; @@ -43,8 +49,26 @@ pub use crate::{ parsing::{tokenize, classify_literal, Token}, }; -use ra_text_edit::AtomTextEdit; -use crate::syntax_node::GreenNode; +/// `Parse` is the result of the parsing: a syntax tree and a collection of +/// errors. +/// +/// Note that we always produce a syntax tree, even for completely invalid +/// files. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Parse { + pub tree: TreeArc, + pub errors: Arc>, +} + +impl Parse { + pub fn ok(self) -> Result, Arc>> { + if self.errors.is_empty() { + Ok(self.tree) + } else { + Err(self.errors) + } + } +} /// `SourceFile` represents a parse tree for a single Rust file. pub use crate::ast::SourceFile; -- cgit v1.2.3 From 90926b9479a0403f7a5d8a94af876d88d42a8237 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 May 2019 11:33:07 +0300 Subject: drop errors from SyntaxNode --- crates/ra_syntax/src/lib.rs | 4 ++-- crates/ra_syntax/src/syntax_node.rs | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index a950870bd..6a4f3ff13 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -74,8 +74,8 @@ impl Parse { pub use crate::ast::SourceFile; impl SourceFile { - fn new(green: GreenNode, errors: Vec) -> TreeArc { - let root = SyntaxNode::new(green, errors); + fn new(green: GreenNode, _errors: Vec) -> TreeArc { + let root = SyntaxNode::new(green); if cfg!(debug_assertions) { validation::validate_block_structure(&root); } diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 80054f529..e4eab6b87 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -9,7 +9,6 @@ use std::{ ops::RangeInclusive, fmt::{self, Write}, - any::Any, borrow::Borrow, iter::successors, }; @@ -133,10 +132,8 @@ pub enum Direction { } impl SyntaxNode { - pub(crate) fn new(green: GreenNode, errors: Vec) -> TreeArc { - let errors: Option> = - if errors.is_empty() { None } else { Some(Box::new(errors)) }; - let ptr = TreeArc(rowan::SyntaxNode::new(green, errors)); + pub(crate) fn new(green: GreenNode) -> TreeArc { + let ptr = TreeArc(rowan::SyntaxNode::new(green, None)); TreeArc::cast(ptr) } @@ -630,8 +627,8 @@ impl SyntaxTreeBuilder { } pub fn finish(self) -> TreeArc { - let (green, errors) = self.finish_raw(); - let node = SyntaxNode::new(green, errors); + let (green, _errors) = self.finish_raw(); + let node = SyntaxNode::new(green); if cfg!(debug_assertions) { crate::validation::validate_block_structure(&node); } -- cgit v1.2.3 From 1cece9f219016152b2e8bc6194fb7f44a441c6db Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 May 2019 11:34:39 +0300 Subject: return errors from tree builder --- crates/ra_syntax/src/syntax_node.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index e4eab6b87..3a9b3ec2f 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -626,13 +626,13 @@ impl SyntaxTreeBuilder { (green, self.errors) } - pub fn finish(self) -> TreeArc { - let (green, _errors) = self.finish_raw(); + pub fn finish(self) -> (TreeArc, Vec) { + let (green, errors) = self.finish_raw(); let node = SyntaxNode::new(green); if cfg!(debug_assertions) { crate::validation::validate_block_structure(&node); } - node + (node, errors) } pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) { -- cgit v1.2.3 From afeaea7051a41269043b1443b9db1e8e44aa4a3e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 16:34:23 +0300 Subject: drop error from SOurceFile constructor --- crates/ra_syntax/src/lib.rs | 8 ++++---- crates/ra_syntax/src/syntax_node.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 6a4f3ff13..f765f621b 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -74,7 +74,7 @@ impl Parse { pub use crate::ast::SourceFile; impl SourceFile { - fn new(green: GreenNode, _errors: Vec) -> TreeArc { + fn new(green: GreenNode) -> TreeArc { let root = SyntaxNode::new(green); if cfg!(debug_assertions) { validation::validate_block_structure(&root); @@ -84,8 +84,8 @@ impl SourceFile { } pub fn parse(text: &str) -> TreeArc { - let (green, errors) = parsing::parse_text(text); - SourceFile::new(green, errors) + let (green, _errors) = parsing::parse_text(text); + SourceFile::new(green) } pub fn reparse(&self, edit: &AtomTextEdit) -> TreeArc { @@ -94,7 +94,7 @@ impl SourceFile { 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, errors)) + .map(|(green_node, _errors, _reparsed_range)| SourceFile::new(green_node)) } fn full_reparse(&self, edit: &AtomTextEdit) -> TreeArc { diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 3a9b3ec2f..ef7a51686 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -383,7 +383,7 @@ impl SyntaxNode { let len = new_children.iter().map(|it| it.text_len()).sum::(); let new_node = GreenNode::new(rowan::SyntaxKind(self.kind() as u16), new_children); let new_file_node = self.replace_with(new_node); - let file = SourceFile::new(new_file_node, Vec::new()); + let file = SourceFile::new(new_file_node); // FIXME: use a more elegant way to re-fetch the node (#1185), make // `range` private afterwards -- cgit v1.2.3 From bc2550b196fbf341ce0168f7dda5498e4d7aaf63 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 16:59:22 +0300 Subject: update tests --- crates/ra_syntax/src/lib.rs | 16 +++++++++++++++- crates/ra_syntax/src/parsing/reparsing.rs | 12 +++++++----- crates/ra_syntax/src/syntax_node.rs | 30 ++++-------------------------- crates/ra_syntax/tests/test.rs | 25 ++++++++++--------------- 4 files changed, 36 insertions(+), 47 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index f765f621b..37320e1ba 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -31,7 +31,7 @@ pub mod ast; #[doc(hidden)] pub mod fuzz; -use std::sync::Arc; +use std::{sync::Arc, fmt::Write}; use ra_text_edit::AtomTextEdit; @@ -68,6 +68,14 @@ impl Parse { Err(self.errors) } } + + pub fn debug_dump(&self) -> String { + let mut buf = self.tree.syntax().debug_dump(); + for err in self.errors.iter() { + writeln!(buf, "err: `{}`", err).unwrap(); + } + buf + } } /// `SourceFile` represents a parse tree for a single Rust file. @@ -83,6 +91,12 @@ impl SourceFile { TreeArc::cast(root) } + pub fn parse2(text: &str) -> Parse { + let (green, errors) = parsing::parse_text(text); + let tree = SourceFile::new(green); + Parse { tree, errors: Arc::new(errors) } + } + pub fn parse(text: &str) -> TreeArc { let (green, _errors) = parsing::parse_text(text); SourceFile::new(green) diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index 3b6687f61..dc913cf2b 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -166,9 +166,11 @@ fn merge_errors( #[cfg(test)] mod tests { + use std::sync::Arc; + use test_utils::{extract_range, assert_eq_text}; - use crate::{SourceFile, AstNode}; + use crate::{SourceFile, AstNode, Parse}; use super::*; fn do_check(before: &str, replace_with: &str, reparsed_len: u32) { @@ -176,19 +178,19 @@ mod tests { let edit = AtomTextEdit::replace(range, replace_with.to_owned()); let after = edit.apply(before.clone()); - let fully_reparsed = SourceFile::parse(&after); + let fully_reparsed = SourceFile::parse2(&after); let incrementally_reparsed = { let f = SourceFile::parse(&before); let edit = AtomTextEdit { delete: range, insert: replace_with.to_string() }; let (green, new_errors, range) = incremental_reparse(f.syntax(), &edit, f.errors()).unwrap(); assert_eq!(range.len(), reparsed_len.into(), "reparsed fragment has wrong length"); - SourceFile::new(green, new_errors) + Parse { tree: SourceFile::new(green), errors: Arc::new(new_errors) } }; assert_eq_text!( - &fully_reparsed.syntax().debug_dump(), - &incrementally_reparsed.syntax().debug_dump(), + &fully_reparsed.tree.syntax().debug_dump(), + &incrementally_reparsed.tree.syntax().debug_dump(), ); } diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index ef7a51686..769125d11 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -256,37 +256,18 @@ impl SyntaxNode { } pub fn debug_dump(&self) -> String { - let mut errors: Vec<_> = match self.ancestors().find_map(SourceFile::cast) { - Some(file) => file.errors(), - None => self.root_data().to_vec(), - }; - errors.sort_by_key(|e| e.offset()); - let mut err_pos = 0; let mut level = 0; let mut buf = String::new(); - macro_rules! indent { - () => { - for _ in 0..level { - buf.push_str(" "); - } - }; - } for event in self.preorder_with_tokens() { match event { WalkEvent::Enter(element) => { - indent!(); + for _ in 0..level { + buf.push_str(" "); + } match element { SyntaxElement::Node(node) => writeln!(buf, "{:?}", node).unwrap(), - SyntaxElement::Token(token) => { - writeln!(buf, "{:?}", token).unwrap(); - let off = token.range().end(); - while err_pos < errors.len() && errors[err_pos].offset() <= off { - indent!(); - writeln!(buf, "err: `{}`", errors[err_pos]).unwrap(); - err_pos += 1; - } - } + SyntaxElement::Token(token) => writeln!(buf, "{:?}", token).unwrap(), } level += 1; } @@ -295,9 +276,6 @@ impl SyntaxNode { } assert_eq!(level, 0); - for err in errors[err_pos..].iter() { - writeln!(buf, "err: `{}`", err).unwrap(); - } buf } diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 91799f8b5..4b711f271 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -8,7 +8,7 @@ use std::{ }; use test_utils::{project_dir, dir_tests, read_text, collect_tests}; -use ra_syntax::{SourceFile, AstNode, fuzz}; +use ra_syntax::{SourceFile, fuzz}; #[test] fn lexer_tests() { @@ -21,26 +21,21 @@ fn lexer_tests() { #[test] fn parser_tests() { dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], |text, path| { - let file = SourceFile::parse(text); - let errors = file.errors(); + let parse = SourceFile::parse2(text); + let errors = parse.errors.as_slice(); assert_eq!( - &*errors, + errors, &[] as &[ra_syntax::SyntaxError], "There should be no errors in the file {:?}", - path.display() + path.display(), ); - file.syntax().debug_dump() + parse.debug_dump() }); dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], |text, path| { - let file = SourceFile::parse(text); - let errors = file.errors(); - assert_ne!( - &*errors, - &[] as &[ra_syntax::SyntaxError], - "There should be errors in the file {:?}", - path.display() - ); - file.syntax().debug_dump() + let parse = SourceFile::parse2(text); + let errors = parse.errors.as_slice(); + assert!(!errors.is_empty(), "There should be errors in the file {:?}", path.display()); + parse.debug_dump() }); } -- cgit v1.2.3 From 310bfe57bd1ea3cd5e22d434ae9d709265af5463 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 17:09:45 +0300 Subject: update test data --- crates/ra_syntax/src/lib.rs | 3 +- .../parser/err/0000_struct_field_missing_comma.txt | 2 +- .../data/parser/err/0001_item_recovery_in_file.txt | 4 +- .../data/parser/err/0002_duplicate_shebang.txt | 2 +- .../tests/data/parser/err/0003_C++_semicolon.txt | 4 +- .../data/parser/err/0004_use_path_bad_segment.txt | 2 +- .../data/parser/err/0005_attribute_recover.txt | 6 +- .../data/parser/err/0006_named_field_recovery.txt | 16 +-- .../data/parser/err/0007_stray_curly_in_file.txt | 6 +- .../data/parser/err/0008_item_block_recovery.txt | 6 +- .../err/0009_broken_struct_type_parameter.txt | 22 ++-- .../data/parser/err/0010_unsafe_lambda_block.txt | 2 +- .../tests/data/parser/err/0011_extern_struct.txt | 2 +- .../tests/data/parser/err/0013_invalid_type.txt | 36 +++--- .../tests/data/parser/err/0014_where_no_bounds.txt | 2 +- .../tests/data/parser/err/0015_curly_in_params.txt | 12 +- .../tests/data/parser/err/0016_missing_semi.txt | 2 +- .../data/parser/err/0017_incomplete_binexpr.txt | 2 +- .../tests/data/parser/err/0018_incomplete_fn.txt | 10 +- .../tests/data/parser/err/0019_let_recover.txt | 20 +-- .../tests/data/parser/err/0020_fn_recover.txt | 6 +- .../data/parser/err/0021_incomplete_param.txt | 4 +- .../tests/data/parser/err/0022_bad_exprs.txt | 78 ++++++------ .../data/parser/err/0023_mismatched_paren.txt | 4 +- .../data/parser/err/0024_many_type_parens.txt | 62 +++++----- .../ra_syntax/tests/data/parser/err/0025_nope.txt | 22 ++-- .../tests/data/parser/err/0026_imp_recovery.txt | 4 +- .../data/parser/err/0027_incomplere_where_for.txt | 4 +- .../tests/data/parser/err/0028_macro_2.0.txt | 134 ++++++++++----------- .../data/parser/err/0029_field_completion.txt | 2 +- .../tests/data/parser/err/0030_string_suffixes.txt | 2 +- .../data/parser/err/0031_block_inner_attrs.txt | 8 +- .../parser/err/0032_match_arms_inner_attrs.txt | 22 ++-- .../parser/err/0033_match_arms_outer_attrs.txt | 6 +- .../inline/err/0001_array_type_missing_semi.txt | 10 +- .../parser/inline/err/0002_misplaced_label_err.txt | 8 +- .../inline/err/0003_pointer_type_no_mutability.txt | 2 +- .../data/parser/inline/err/0004_impl_type.txt | 8 +- .../inline/err/0005_fn_pointer_type_missing_fn.txt | 10 +- .../parser/inline/err/0006_unsafe_block_in_mod.txt | 4 +- .../inline/err/0007_async_without_semicolon.txt | 2 +- .../tests/data/parser/inline/err/0008_pub_expr.txt | 2 +- .../inline/err/0009_attr_on_expr_not_allowed.txt | 4 +- .../inline/err/0010_bad_tuple_index_expr.txt | 6 +- .../parser/inline/err/0010_wrong_order_fns.txt | 4 +- 45 files changed, 290 insertions(+), 289 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 37320e1ba..6574eeed1 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -92,8 +92,9 @@ impl SourceFile { } pub fn parse2(text: &str) -> Parse { - let (green, errors) = parsing::parse_text(text); + let (green, mut errors) = parsing::parse_text(text); let tree = SourceFile::new(green); + errors.extend(validation::validate(&tree)); Parse { tree, errors: Arc::new(errors) } } diff --git a/crates/ra_syntax/tests/data/parser/err/0000_struct_field_missing_comma.txt b/crates/ra_syntax/tests/data/parser/err/0000_struct_field_missing_comma.txt index 21ef31ba8..0662052c5 100644 --- a/crates/ra_syntax/tests/data/parser/err/0000_struct_field_missing_comma.txt +++ b/crates/ra_syntax/tests/data/parser/err/0000_struct_field_missing_comma.txt @@ -18,7 +18,6 @@ SOURCE_FILE@[0; 34) PATH_SEGMENT@[18; 21) NAME_REF@[18; 21) IDENT@[18; 21) "u32" - err: `expected COMMA` WHITESPACE@[21; 26) "\n " NAMED_FIELD_DEF@[26; 32) NAME@[26; 27) @@ -32,3 +31,4 @@ SOURCE_FILE@[0; 34) IDENT@[29; 32) "u32" WHITESPACE@[32; 33) "\n" R_CURLY@[33; 34) "}" +err: `expected COMMA` diff --git a/crates/ra_syntax/tests/data/parser/err/0001_item_recovery_in_file.txt b/crates/ra_syntax/tests/data/parser/err/0001_item_recovery_in_file.txt index d7762c089..45044fe0a 100644 --- a/crates/ra_syntax/tests/data/parser/err/0001_item_recovery_in_file.txt +++ b/crates/ra_syntax/tests/data/parser/err/0001_item_recovery_in_file.txt @@ -1,9 +1,7 @@ SOURCE_FILE@[0; 21) ERROR@[0; 2) IF_KW@[0; 2) "if" - err: `expected an item` WHITESPACE@[2; 3) " " - err: `expected an item` ERROR@[3; 8) MATCH_KW@[3; 8) "match" WHITESPACE@[8; 10) "\n\n" @@ -16,3 +14,5 @@ SOURCE_FILE@[0; 21) NAMED_FIELD_DEF_LIST@[19; 21) L_CURLY@[19; 20) "{" R_CURLY@[20; 21) "}" +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0002_duplicate_shebang.txt b/crates/ra_syntax/tests/data/parser/err/0002_duplicate_shebang.txt index 76642f43b..1506acdfd 100644 --- a/crates/ra_syntax/tests/data/parser/err/0002_duplicate_shebang.txt +++ b/crates/ra_syntax/tests/data/parser/err/0002_duplicate_shebang.txt @@ -1,7 +1,7 @@ SOURCE_FILE@[0; 42) SHEBANG@[0; 20) "#!/use/bin/env rusti" WHITESPACE@[20; 21) "\n" - err: `expected an item` ERROR@[21; 41) SHEBANG@[21; 41) "#!/use/bin/env rusti" WHITESPACE@[41; 42) "\n" +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0003_C++_semicolon.txt b/crates/ra_syntax/tests/data/parser/err/0003_C++_semicolon.txt index b52aaa368..586baf1bb 100644 --- a/crates/ra_syntax/tests/data/parser/err/0003_C++_semicolon.txt +++ b/crates/ra_syntax/tests/data/parser/err/0003_C++_semicolon.txt @@ -33,7 +33,7 @@ SOURCE_FILE@[0; 40) COMMA@[36; 37) "," WHITESPACE@[37; 38) "\n" R_CURLY@[38; 39) "}" - err: `expected item, found `;` -consider removing this semicolon` ERROR@[39; 40) SEMI@[39; 40) ";" +err: `expected item, found `;` +consider removing this semicolon` diff --git a/crates/ra_syntax/tests/data/parser/err/0004_use_path_bad_segment.txt b/crates/ra_syntax/tests/data/parser/err/0004_use_path_bad_segment.txt index fb44f21ea..a70223912 100644 --- a/crates/ra_syntax/tests/data/parser/err/0004_use_path_bad_segment.txt +++ b/crates/ra_syntax/tests/data/parser/err/0004_use_path_bad_segment.txt @@ -9,8 +9,8 @@ SOURCE_FILE@[0; 12) NAME_REF@[4; 7) IDENT@[4; 7) "foo" COLONCOLON@[7; 9) "::" - err: `expected identifier` PATH_SEGMENT@[9; 11) ERROR@[9; 11) INT_NUMBER@[9; 11) "92" SEMI@[11; 12) ";" +err: `expected identifier` diff --git a/crates/ra_syntax/tests/data/parser/err/0005_attribute_recover.txt b/crates/ra_syntax/tests/data/parser/err/0005_attribute_recover.txt index 1e27522bf..9a6da88fe 100644 --- a/crates/ra_syntax/tests/data/parser/err/0005_attribute_recover.txt +++ b/crates/ra_syntax/tests/data/parser/err/0005_attribute_recover.txt @@ -49,7 +49,7 @@ SOURCE_FILE@[0; 54) L_CURLY@[50; 51) "{" WHITESPACE@[51; 52) "\n" R_CURLY@[52; 53) "}" - err: `expected R_PAREN` - err: `expected R_BRACK` - err: `expected an item` WHITESPACE@[53; 54) "\n" +err: `expected R_PAREN` +err: `expected R_BRACK` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0006_named_field_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0006_named_field_recovery.txt index d47b98ed4..5effbb60f 100644 --- a/crates/ra_syntax/tests/data/parser/err/0006_named_field_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0006_named_field_recovery.txt @@ -23,25 +23,17 @@ SOURCE_FILE@[0; 74) VISIBILITY@[27; 30) PUB_KW@[27; 30) "pub" WHITESPACE@[30; 31) " " - err: `expected field declaration` ERROR@[31; 33) INT_NUMBER@[31; 33) "92" - err: `expected COMMA` WHITESPACE@[33; 38) "\n " - err: `expected field declaration` ERROR@[38; 39) PLUS@[38; 39) "+" - err: `expected COMMA` WHITESPACE@[39; 40) " " - err: `expected field declaration` ERROR@[40; 41) MINUS@[40; 41) "-" - err: `expected COMMA` WHITESPACE@[41; 42) " " - err: `expected field declaration` ERROR@[42; 43) STAR@[42; 43) "*" - err: `expected COMMA` WHITESPACE@[43; 48) "\n " NAMED_FIELD_DEF@[48; 58) VISIBILITY@[48; 51) @@ -72,3 +64,11 @@ SOURCE_FILE@[0; 74) WHITESPACE@[71; 72) "\n" R_CURLY@[72; 73) "}" WHITESPACE@[73; 74) "\n" +err: `expected field declaration` +err: `expected COMMA` +err: `expected field declaration` +err: `expected COMMA` +err: `expected field declaration` +err: `expected COMMA` +err: `expected field declaration` +err: `expected COMMA` diff --git a/crates/ra_syntax/tests/data/parser/err/0007_stray_curly_in_file.txt b/crates/ra_syntax/tests/data/parser/err/0007_stray_curly_in_file.txt index 94066ed05..ff59f5d71 100644 --- a/crates/ra_syntax/tests/data/parser/err/0007_stray_curly_in_file.txt +++ b/crates/ra_syntax/tests/data/parser/err/0007_stray_curly_in_file.txt @@ -1,7 +1,6 @@ SOURCE_FILE@[0; 31) ERROR@[0; 1) R_CURLY@[0; 1) "}" - err: `unmatched `}`` WHITESPACE@[1; 3) "\n\n" STRUCT_DEF@[3; 12) STRUCT_KW@[3; 9) "struct" @@ -10,7 +9,6 @@ SOURCE_FILE@[0; 31) IDENT@[10; 11) "S" SEMI@[11; 12) ";" WHITESPACE@[12; 14) "\n\n" - err: `unmatched `}`` ERROR@[14; 15) R_CURLY@[14; 15) "}" WHITESPACE@[15; 17) "\n\n" @@ -26,7 +24,9 @@ SOURCE_FILE@[0; 31) L_CURLY@[25; 26) "{" R_CURLY@[26; 27) "}" WHITESPACE@[27; 29) "\n\n" - err: `unmatched `}`` ERROR@[29; 30) R_CURLY@[29; 30) "}" WHITESPACE@[30; 31) "\n" +err: `unmatched `}`` +err: `unmatched `}`` +err: `unmatched `}`` diff --git a/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt index 6f5a27856..75f6b3b9c 100644 --- a/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0008_item_block_recovery.txt @@ -18,13 +18,10 @@ SOURCE_FILE@[0; 95) PATH_SEGMENT@[14; 17) NAME_REF@[14; 17) IDENT@[14; 17) "bar" - err: `expected EXCL` TOKEN_TREE@[17; 19) L_PAREN@[17; 18) "(" R_PAREN@[18; 19) ")" - err: `expected SEMI` WHITESPACE@[19; 20) " " - err: `expected an item` ERROR@[20; 80) L_CURLY@[20; 21) "{" WHITESPACE@[21; 26) "\n " @@ -75,3 +72,6 @@ SOURCE_FILE@[0; 95) WHITESPACE@[92; 93) "\n" R_CURLY@[93; 94) "}" WHITESPACE@[94; 95) "\n" +err: `expected EXCL` +err: `expected SEMI` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt b/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt index 80568b5bd..8aa8c3ef4 100644 --- a/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt +++ b/crates/ra_syntax/tests/data/parser/err/0009_broken_struct_type_parameter.txt @@ -6,25 +6,17 @@ SOURCE_FILE@[0; 43) IDENT@[7; 8) "S" TYPE_PARAM_LIST@[8; 11) L_ANGLE@[8; 9) "<" - err: `expected type parameter` ERROR@[9; 11) INT_NUMBER@[9; 11) "90" - err: `expected COMMA` - err: `expected R_ANGLE` - err: `expected `;`, `{`, or `(`` WHITESPACE@[11; 12) " " - err: `expected an item` ERROR@[12; 13) PLUS@[12; 13) "+" WHITESPACE@[13; 14) " " - err: `expected an item` ERROR@[14; 15) INT_NUMBER@[14; 15) "2" - err: `expected an item` ERROR@[15; 16) R_ANGLE@[15; 16) ">" WHITESPACE@[16; 17) " " - err: `expected an item` ERROR@[17; 31) L_CURLY@[17; 18) "{" WHITESPACE@[18; 23) "\n " @@ -34,12 +26,9 @@ SOURCE_FILE@[0; 43) PATH_SEGMENT@[23; 24) NAME_REF@[23; 24) IDENT@[23; 24) "f" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[24; 25) ERROR@[24; 25) COLON@[24; 25) ":" - err: `expected SEMI` WHITESPACE@[25; 26) " " PATH_EXPR@[26; 29) PATH@[26; 29) @@ -56,3 +45,14 @@ SOURCE_FILE@[0; 43) IDENT@[40; 41) "T" SEMI@[41; 42) ";" WHITESPACE@[42; 43) "\n" +err: `expected type parameter` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected `;`, `{`, or `(`` +err: `expected an item` +err: `expected an item` +err: `expected an item` +err: `expected an item` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/err/0010_unsafe_lambda_block.txt b/crates/ra_syntax/tests/data/parser/err/0010_unsafe_lambda_block.txt index 36982085a..22a1727f0 100644 --- a/crates/ra_syntax/tests/data/parser/err/0010_unsafe_lambda_block.txt +++ b/crates/ra_syntax/tests/data/parser/err/0010_unsafe_lambda_block.txt @@ -23,7 +23,6 @@ SOURCE_FILE@[0; 42) TUPLE_TYPE@[22; 24) L_PAREN@[22; 23) "(" R_PAREN@[23; 24) ")" - err: `expected `{`` WHITESPACE@[24; 25) " " BLOCK_EXPR@[25; 38) UNSAFE_KW@[25; 31) "unsafe" @@ -40,3 +39,4 @@ SOURCE_FILE@[0; 42) WHITESPACE@[39; 40) "\n" R_CURLY@[40; 41) "}" WHITESPACE@[41; 42) "\n" +err: `expected `{`` diff --git a/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt b/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt index 3fb0a77ef..ee2a29d9f 100644 --- a/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt +++ b/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt @@ -2,7 +2,6 @@ SOURCE_FILE@[0; 19) ERROR@[0; 6) ABI@[0; 6) EXTERN_KW@[0; 6) "extern" - err: `expected fn, trait or impl` WHITESPACE@[6; 7) " " STRUCT_DEF@[7; 18) STRUCT_KW@[7; 13) "struct" @@ -11,3 +10,4 @@ SOURCE_FILE@[0; 19) IDENT@[14; 17) "Foo" SEMI@[17; 18) ";" WHITESPACE@[18; 19) "\n" +err: `expected fn, trait or impl` diff --git a/crates/ra_syntax/tests/data/parser/err/0013_invalid_type.txt b/crates/ra_syntax/tests/data/parser/err/0013_invalid_type.txt index 47b992b0a..1f5cc55c0 100644 --- a/crates/ra_syntax/tests/data/parser/err/0013_invalid_type.txt +++ b/crates/ra_syntax/tests/data/parser/err/0013_invalid_type.txt @@ -43,17 +43,9 @@ SOURCE_FILE@[0; 86) IDENT@[63; 66) "Box" TYPE_ARG_LIST@[66; 68) L_ANGLE@[66; 67) "<" - err: `expected type` TYPE_ARG@[67; 68) ERROR@[67; 68) AT@[67; 68) "@" - err: `expected COMMA` - err: `expected R_ANGLE` - err: `expected COMMA` - err: `expected R_ANGLE` - err: `expected COMMA` - err: `expected R_ANGLE` - err: `expected COMMA` WHITESPACE@[68; 69) " " POS_FIELD_DEF@[69; 72) PATH_TYPE@[69; 72) @@ -61,29 +53,37 @@ SOURCE_FILE@[0; 86) PATH_SEGMENT@[69; 72) NAME_REF@[69; 72) IDENT@[69; 72) "Any" - err: `expected COMMA` - err: `expected a type` - err: `expected R_PAREN` - err: `expected SEMI` - err: `expected an item` ERROR@[72; 72) ERROR@[72; 73) R_ANGLE@[72; 73) ">" - err: `expected an item` ERROR@[73; 74) COMMA@[73; 74) "," WHITESPACE@[74; 79) "\n " - err: `expected an item` ERROR@[79; 80) R_ANGLE@[79; 80) ">" - err: `expected an item` ERROR@[80; 81) R_ANGLE@[80; 81) ">" WHITESPACE@[81; 82) "\n" - err: `expected an item` ERROR@[82; 83) R_PAREN@[82; 83) ")" - err: `expected an item` ERROR@[83; 84) SEMI@[83; 84) ";" WHITESPACE@[84; 86) "\n\n" +err: `expected type` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected COMMA` +err: `expected COMMA` +err: `expected a type` +err: `expected R_PAREN` +err: `expected SEMI` +err: `expected an item` +err: `expected an item` +err: `expected an item` +err: `expected an item` +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0014_where_no_bounds.txt b/crates/ra_syntax/tests/data/parser/err/0014_where_no_bounds.txt index 52ad7bef7..276a58b69 100644 --- a/crates/ra_syntax/tests/data/parser/err/0014_where_no_bounds.txt +++ b/crates/ra_syntax/tests/data/parser/err/0014_where_no_bounds.txt @@ -23,9 +23,9 @@ SOURCE_FILE@[0; 23) PATH_SEGMENT@[18; 19) NAME_REF@[18; 19) IDENT@[18; 19) "T" - err: `expected colon` WHITESPACE@[19; 20) " " BLOCK@[20; 22) L_CURLY@[20; 21) "{" R_CURLY@[21; 22) "}" WHITESPACE@[22; 23) "\n" +err: `expected colon` diff --git a/crates/ra_syntax/tests/data/parser/err/0015_curly_in_params.txt b/crates/ra_syntax/tests/data/parser/err/0015_curly_in_params.txt index 1350980f2..8f93b832d 100644 --- a/crates/ra_syntax/tests/data/parser/err/0015_curly_in_params.txt +++ b/crates/ra_syntax/tests/data/parser/err/0015_curly_in_params.txt @@ -6,19 +6,19 @@ SOURCE_FILE@[0; 14) IDENT@[3; 6) "foo" PARAM_LIST@[6; 7) L_PAREN@[6; 7) "(" - err: `expected value parameter` - err: `expected R_PAREN` - err: `expected a block` - err: `unmatched `}`` ERROR@[7; 8) R_CURLY@[7; 8) "}" - err: `expected an item` ERROR@[8; 9) R_PAREN@[8; 9) ")" WHITESPACE@[9; 10) " " - err: `expected an item` ERROR@[10; 13) L_CURLY@[10; 11) "{" WHITESPACE@[11; 12) "\n" R_CURLY@[12; 13) "}" WHITESPACE@[13; 14) "\n" +err: `expected value parameter` +err: `expected R_PAREN` +err: `expected a block` +err: `unmatched `}`` +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/err/0016_missing_semi.txt b/crates/ra_syntax/tests/data/parser/err/0016_missing_semi.txt index dd60814a0..105e45a35 100644 --- a/crates/ra_syntax/tests/data/parser/err/0016_missing_semi.txt +++ b/crates/ra_syntax/tests/data/parser/err/0016_missing_semi.txt @@ -29,7 +29,6 @@ SOURCE_FILE@[0; 56) INT_NUMBER@[31; 32) "2" WHITESPACE@[32; 37) "\n " R_PAREN@[37; 38) ")" - err: `expected SEMI` WHITESPACE@[38; 43) "\n " EXPR_STMT@[43; 53) RETURN_EXPR@[43; 52) @@ -41,3 +40,4 @@ SOURCE_FILE@[0; 56) WHITESPACE@[53; 54) "\n" R_CURLY@[54; 55) "}" WHITESPACE@[55; 56) "\n" +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/err/0017_incomplete_binexpr.txt b/crates/ra_syntax/tests/data/parser/err/0017_incomplete_binexpr.txt index f115eb1dd..751740620 100644 --- a/crates/ra_syntax/tests/data/parser/err/0017_incomplete_binexpr.txt +++ b/crates/ra_syntax/tests/data/parser/err/0017_incomplete_binexpr.txt @@ -40,7 +40,7 @@ SOURCE_FILE@[0; 47) INT_NUMBER@[41; 42) "1" WHITESPACE@[42; 43) " " PLUS@[43; 44) "+" - err: `expected expression` WHITESPACE@[44; 45) "\n" R_CURLY@[45; 46) "}" WHITESPACE@[46; 47) "\n" +err: `expected expression` diff --git a/crates/ra_syntax/tests/data/parser/err/0018_incomplete_fn.txt b/crates/ra_syntax/tests/data/parser/err/0018_incomplete_fn.txt index 9996cf824..82908b8f2 100644 --- a/crates/ra_syntax/tests/data/parser/err/0018_incomplete_fn.txt +++ b/crates/ra_syntax/tests/data/parser/err/0018_incomplete_fn.txt @@ -21,9 +21,6 @@ SOURCE_FILE@[0; 183) PARAM@[33; 34) REF_PAT@[33; 34) AMP@[33; 34) "&" - err: `expected pattern` - err: `expected COLON` - err: `expected type` R_PAREN@[34; 35) ")" WHITESPACE@[35; 36) " " RET_TYPE@[36; 46) @@ -124,8 +121,11 @@ SOURCE_FILE@[0; 183) WHITESPACE@[169; 170) " " NAME@[170; 180) IDENT@[170; 180) "set_parent" - err: `expected function arguments` - err: `expected a block` WHITESPACE@[180; 181) "\n" R_CURLY@[181; 182) "}" WHITESPACE@[182; 183) "\n" +err: `expected pattern` +err: `expected COLON` +err: `expected type` +err: `expected function arguments` +err: `expected a block` diff --git a/crates/ra_syntax/tests/data/parser/err/0019_let_recover.txt b/crates/ra_syntax/tests/data/parser/err/0019_let_recover.txt index c12649d5e..4a1b84ee5 100644 --- a/crates/ra_syntax/tests/data/parser/err/0019_let_recover.txt +++ b/crates/ra_syntax/tests/data/parser/err/0019_let_recover.txt @@ -19,8 +19,6 @@ SOURCE_FILE@[0; 139) IDENT@[19; 22) "foo" WHITESPACE@[22; 23) " " EQ@[23; 24) "=" - err: `expected expression` - err: `expected SEMI` WHITESPACE@[24; 29) "\n " LET_STMT@[29; 41) LET_KW@[29; 32) "let" @@ -37,8 +35,6 @@ SOURCE_FILE@[0; 139) WHITESPACE@[41; 46) "\n " LET_STMT@[46; 49) LET_KW@[46; 49) "let" - err: `expected pattern` - err: `expected SEMI` WHITESPACE@[49; 54) "\n " LET_STMT@[54; 67) LET_KW@[54; 57) "let" @@ -55,8 +51,6 @@ SOURCE_FILE@[0; 139) WHITESPACE@[67; 72) "\n " LET_STMT@[72; 75) LET_KW@[72; 75) "let" - err: `expected pattern` - err: `expected SEMI` WHITESPACE@[75; 80) "\n " EXPR_STMT@[80; 90) IF_EXPR@[80; 90) @@ -72,8 +66,6 @@ SOURCE_FILE@[0; 139) WHITESPACE@[90; 95) "\n " LET_STMT@[95; 98) LET_KW@[95; 98) "let" - err: `expected pattern` - err: `expected SEMI` WHITESPACE@[98; 103) "\n " EXPR_STMT@[103; 116) WHILE_EXPR@[103; 116) @@ -89,8 +81,6 @@ SOURCE_FILE@[0; 139) WHITESPACE@[116; 121) "\n " LET_STMT@[121; 124) LET_KW@[121; 124) "let" - err: `expected pattern` - err: `expected SEMI` WHITESPACE@[124; 129) "\n " LOOP_EXPR@[129; 136) LOOP_KW@[129; 133) "loop" @@ -101,3 +91,13 @@ SOURCE_FILE@[0; 139) WHITESPACE@[136; 137) "\n" R_CURLY@[137; 138) "}" WHITESPACE@[138; 139) "\n" +err: `expected expression` +err: `expected SEMI` +err: `expected pattern` +err: `expected SEMI` +err: `expected pattern` +err: `expected SEMI` +err: `expected pattern` +err: `expected SEMI` +err: `expected pattern` +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/err/0020_fn_recover.txt b/crates/ra_syntax/tests/data/parser/err/0020_fn_recover.txt index b48bd5dee..d7ac73afa 100644 --- a/crates/ra_syntax/tests/data/parser/err/0020_fn_recover.txt +++ b/crates/ra_syntax/tests/data/parser/err/0020_fn_recover.txt @@ -1,9 +1,6 @@ SOURCE_FILE@[0; 16) FN_DEF@[0; 2) FN_KW@[0; 2) "fn" - err: `expected a name` - err: `expected function arguments` - err: `expected a block` WHITESPACE@[2; 4) "\n\n" FN_DEF@[4; 15) FN_KW@[4; 6) "fn" @@ -18,3 +15,6 @@ SOURCE_FILE@[0; 16) L_CURLY@[13; 14) "{" R_CURLY@[14; 15) "}" WHITESPACE@[15; 16) "\n" +err: `expected a name` +err: `expected function arguments` +err: `expected a block` diff --git a/crates/ra_syntax/tests/data/parser/err/0021_incomplete_param.txt b/crates/ra_syntax/tests/data/parser/err/0021_incomplete_param.txt index 81b52c8ce..086224eee 100644 --- a/crates/ra_syntax/tests/data/parser/err/0021_incomplete_param.txt +++ b/crates/ra_syntax/tests/data/parser/err/0021_incomplete_param.txt @@ -23,8 +23,6 @@ SOURCE_FILE@[0; 22) BIND_PAT@[15; 16) NAME@[15; 16) IDENT@[15; 16) "y" - err: `expected COLON` - err: `expected type` R_PAREN@[16; 17) ")" WHITESPACE@[17; 18) " " BLOCK@[18; 21) @@ -32,3 +30,5 @@ SOURCE_FILE@[0; 22) WHITESPACE@[19; 20) "\n" R_CURLY@[20; 21) "}" WHITESPACE@[21; 22) "\n" +err: `expected COLON` +err: `expected type` diff --git a/crates/ra_syntax/tests/data/parser/err/0022_bad_exprs.txt b/crates/ra_syntax/tests/data/parser/err/0022_bad_exprs.txt index 6dfdfc343..d7a5fa1d2 100644 --- a/crates/ra_syntax/tests/data/parser/err/0022_bad_exprs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0022_bad_exprs.txt @@ -21,34 +21,23 @@ SOURCE_FILE@[0; 112) LITERAL@[13; 14) INT_NUMBER@[13; 14) "2" COMMA@[14; 15) "," - err: `expected expression` - err: `expected R_BRACK` - err: `expected SEMI` WHITESPACE@[15; 16) " " - err: `expected expression` EXPR_STMT@[16; 17) ERROR@[16; 17) AT@[16; 17) "@" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[17; 18) ERROR@[17; 18) COMMA@[17; 18) "," - err: `expected SEMI` WHITESPACE@[18; 19) " " STRUCT_DEF@[19; 26) STRUCT_KW@[19; 25) "struct" - err: `expected a name` ERROR@[25; 26) COMMA@[25; 26) "," - err: `expected `;`, `{`, or `(`` WHITESPACE@[26; 27) " " LET_STMT@[27; 31) LET_KW@[27; 30) "let" - err: `expected pattern` ERROR@[30; 31) R_BRACK@[30; 31) "]" - err: `expected SEMI` WHITESPACE@[31; 32) " " R_CURLY@[32; 33) "}" WHITESPACE@[33; 34) "\n" @@ -80,35 +69,22 @@ SOURCE_FILE@[0; 112) LITERAL@[50; 51) INT_NUMBER@[50; 51) "2" COMMA@[51; 52) "," - err: `expected expression` - err: `expected SEMI` WHITESPACE@[52; 53) " " - err: `expected expression` EXPR_STMT@[53; 54) ERROR@[53; 54) AT@[53; 54) "@" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[54; 55) ERROR@[54; 55) COMMA@[54; 55) "," - err: `expected SEMI` WHITESPACE@[55; 56) " " IMPL_BLOCK@[56; 60) IMPL_KW@[56; 60) "impl" - err: `expected type` - err: `expected `{`` - err: `expected expression` EXPR_STMT@[60; 61) ERROR@[60; 61) COMMA@[60; 61) "," - err: `expected SEMI` WHITESPACE@[61; 62) " " LET_STMT@[62; 65) LET_KW@[62; 65) "let" - err: `expected pattern` - err: `expected SEMI` - err: `expected expression` ERROR@[65; 66) R_PAREN@[65; 66) ")" WHITESPACE@[66; 67) " " @@ -145,45 +121,69 @@ SOURCE_FILE@[0; 112) LITERAL@[89; 90) INT_NUMBER@[89; 90) "2" COMMA@[90; 91) "," - err: `expected expression` - err: `expected SEMI` WHITESPACE@[91; 92) " " - err: `expected expression` EXPR_STMT@[92; 93) ERROR@[92; 93) AT@[92; 93) "@" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[93; 94) ERROR@[93; 94) COMMA@[93; 94) "," - err: `expected SEMI` WHITESPACE@[94; 95) " " - err: `expected expression` EXPR_STMT@[95; 96) ERROR@[95; 96) R_BRACK@[95; 96) "]" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[96; 97) ERROR@[96; 97) COMMA@[96; 97) "," - err: `expected SEMI` WHITESPACE@[97; 98) " " TRAIT_DEF@[98; 104) TRAIT_KW@[98; 103) "trait" - err: `expected a name` ERROR@[103; 104) COMMA@[103; 104) "," - err: `expected `{`` WHITESPACE@[104; 105) " " LET_STMT@[105; 108) LET_KW@[105; 108) "let" - err: `expected pattern` - err: `expected SEMI` - err: `expected expression` ERROR@[108; 109) R_PAREN@[108; 109) ")" WHITESPACE@[109; 110) " " R_CURLY@[110; 111) "}" WHITESPACE@[111; 112) "\n" +err: `expected expression` +err: `expected R_BRACK` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected a name` +err: `expected `;`, `{`, or `(`` +err: `expected pattern` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected type` +err: `expected `{`` +err: `expected expression` +err: `expected SEMI` +err: `expected pattern` +err: `expected SEMI` +err: `expected expression` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected a name` +err: `expected `{`` +err: `expected pattern` +err: `expected SEMI` +err: `expected expression` diff --git a/crates/ra_syntax/tests/data/parser/err/0023_mismatched_paren.txt b/crates/ra_syntax/tests/data/parser/err/0023_mismatched_paren.txt index 469d35082..143600e67 100644 --- a/crates/ra_syntax/tests/data/parser/err/0023_mismatched_paren.txt +++ b/crates/ra_syntax/tests/data/parser/err/0023_mismatched_paren.txt @@ -31,13 +31,13 @@ SOURCE_FILE@[0; 94) COMMA@[44; 45) "," WHITESPACE@[45; 46) " " FLOAT_NUMBER@[46; 49) "2.0" - err: `unmatched `}`` WHITESPACE@[49; 54) "\n " R_CURLY@[54; 55) "}" WHITESPACE@[55; 56) " " COMMENT@[56; 91) "//~ ERROR incorrect c ..." WHITESPACE@[91; 92) "\n" - err: `unmatched `}`` ERROR@[92; 93) R_CURLY@[92; 93) "}" WHITESPACE@[93; 94) "\n" +err: `unmatched `}`` +err: `unmatched `}`` diff --git a/crates/ra_syntax/tests/data/parser/err/0024_many_type_parens.txt b/crates/ra_syntax/tests/data/parser/err/0024_many_type_parens.txt index 0fb73d838..4f505fa76 100644 --- a/crates/ra_syntax/tests/data/parser/err/0024_many_type_parens.txt +++ b/crates/ra_syntax/tests/data/parser/err/0024_many_type_parens.txt @@ -103,8 +103,6 @@ SOURCE_FILE@[0; 240) NAME_REF@[83; 87) IDENT@[83; 87) "Copy" R_PAREN@[87; 88) ")" - err: `expected COMMA` - err: `expected R_ANGLE` WHITESPACE@[88; 89) " " PLUS@[89; 90) "+" WHITESPACE@[90; 91) " " @@ -141,8 +139,6 @@ SOURCE_FILE@[0; 240) LIFETIME@[117; 119) "\'a" R_ANGLE@[119; 120) ">" R_PAREN@[120; 121) ")" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[121; 123) ERROR@[121; 122) R_ANGLE@[121; 122) ">" @@ -165,54 +161,35 @@ SOURCE_FILE@[0; 240) TYPE_ARG@[139; 141) PAREN_TYPE@[139; 141) L_PAREN@[139; 140) "(" - err: `expected type` ERROR@[140; 141) QUESTION@[140; 141) "?" - err: `expected R_PAREN` - err: `expected COMMA` - err: `expected R_ANGLE` - err: `expected SEMI` EXPR_STMT@[141; 146) PATH_EXPR@[141; 146) PATH@[141; 146) PATH_SEGMENT@[141; 146) NAME_REF@[141; 146) IDENT@[141; 146) "Sized" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[146; 147) ERROR@[146; 147) R_PAREN@[146; 147) ")" - err: `expected SEMI` WHITESPACE@[147; 148) " " - err: `expected expression` EXPR_STMT@[148; 149) ERROR@[148; 149) PLUS@[148; 149) "+" - err: `expected SEMI` WHITESPACE@[149; 150) " " EXPR_STMT@[150; 151) PAREN_EXPR@[150; 151) L_PAREN@[150; 151) "(" - err: `expected expression` - err: `expected R_PAREN` - err: `expected SEMI` EXPR_STMT@[151; 157) FOR_EXPR@[151; 157) FOR_KW@[151; 154) "for" - err: `expected pattern` ERROR@[154; 155) L_ANGLE@[154; 155) "<" - err: `expected IN_KW` - err: `expected expression` ERROR@[155; 157) LIFETIME@[155; 157) "\'a" - err: `expected a block` - err: `expected expression` EXPR_STMT@[157; 158) ERROR@[157; 158) R_ANGLE@[157; 158) ">" - err: `expected SEMI` WHITESPACE@[158; 159) " " EXPR_STMT@[159; 180) BIN_EXPR@[159; 180) @@ -225,11 +202,9 @@ SOURCE_FILE@[0; 240) NAME_REF@[159; 164) IDENT@[159; 164) "Trait" L_ANGLE@[164; 165) "<" - err: `expected expression` ERROR@[165; 167) LIFETIME@[165; 167) "\'a" R_ANGLE@[167; 168) ">" - err: `expected expression` ERROR@[168; 169) R_PAREN@[168; 169) ")" WHITESPACE@[169; 170) " " @@ -244,10 +219,8 @@ SOURCE_FILE@[0; 240) IDENT@[173; 177) "Copy" R_PAREN@[177; 178) ")" R_ANGLE@[178; 179) ">" - err: `expected expression` ERROR@[179; 180) SEMI@[179; 180) ";" - err: `expected SEMI` WHITESPACE@[180; 185) "\n " LET_STMT@[185; 235) LET_KW@[185; 188) "let" @@ -288,8 +261,6 @@ SOURCE_FILE@[0; 240) LIFETIME@[211; 213) "\'a" R_ANGLE@[213; 214) ">" R_PAREN@[214; 215) ")" - err: `expected COMMA` - err: `expected R_ANGLE` WHITESPACE@[215; 216) " " PLUS@[216; 217) "+" WHITESPACE@[217; 218) " " @@ -313,8 +284,6 @@ SOURCE_FILE@[0; 240) NAME_REF@[229; 234) IDENT@[229; 234) "Sized" R_PAREN@[234; 235) ")" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[235; 237) ERROR@[235; 236) R_ANGLE@[235; 236) ">" @@ -322,3 +291,34 @@ SOURCE_FILE@[0; 240) WHITESPACE@[237; 238) "\n" R_CURLY@[238; 239) "}" WHITESPACE@[239; 240) "\n" +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected SEMI` +err: `expected expression` +err: `expected type` +err: `expected R_PAREN` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected SEMI` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected R_PAREN` +err: `expected SEMI` +err: `expected pattern` +err: `expected IN_KW` +err: `expected expression` +err: `expected a block` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected expression` +err: `expected expression` +err: `expected SEMI` +err: `expected COMMA` +err: `expected R_ANGLE` +err: `expected SEMI` +err: `expected expression` diff --git a/crates/ra_syntax/tests/data/parser/err/0025_nope.txt b/crates/ra_syntax/tests/data/parser/err/0025_nope.txt index b8d769947..a1bd8647a 100644 --- a/crates/ra_syntax/tests/data/parser/err/0025_nope.txt +++ b/crates/ra_syntax/tests/data/parser/err/0025_nope.txt @@ -50,14 +50,10 @@ SOURCE_FILE@[0; 575) NAME@[91; 94) IDENT@[91; 94) "abc" COLON@[94; 95) ":" - err: `expected type` - err: `expected COMMA` WHITESPACE@[95; 96) " " - err: `expected field` ERROR@[96; 98) L_CURLY@[96; 97) "{" R_CURLY@[97; 98) "}" - err: `expected field declaration` ERROR@[98; 99) COMMA@[98; 99) "," WHITESPACE@[99; 100) " " @@ -159,17 +155,11 @@ SOURCE_FILE@[0; 575) PATH_SEGMENT@[368; 371) NAME_REF@[368; 371) IDENT@[368; 371) "i32" - err: `expected COMMA` WHITESPACE@[371; 372) " " - err: `expected a type` - err: `expected R_PAREN` - err: `expected COMMA` - err: `expected enum variant` ERROR@[372; 372) ERROR@[372; 374) L_CURLY@[372; 373) "{" R_CURLY@[373; 374) "}" - err: `expected enum variant` ERROR@[374; 375) R_PAREN@[374; 375) ")" WHITESPACE@[375; 376) " " @@ -192,7 +182,6 @@ SOURCE_FILE@[0; 575) WHITESPACE@[505; 506) " " EQ@[506; 507) "=" WHITESPACE@[507; 508) " " - err: `expected expression` ERROR@[508; 509) UNDERSCORE@[508; 509) "_" SEMI@[509; 510) ";" @@ -201,3 +190,14 @@ SOURCE_FILE@[0; 575) WHITESPACE@[572; 573) "\n" R_CURLY@[573; 574) "}" WHITESPACE@[574; 575) "\n" +err: `expected type` +err: `expected COMMA` +err: `expected field` +err: `expected field declaration` +err: `expected COMMA` +err: `expected a type` +err: `expected R_PAREN` +err: `expected COMMA` +err: `expected enum variant` +err: `expected enum variant` +err: `expected expression` diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt index cfd06c9c9..f473718dc 100644 --- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt @@ -16,8 +16,6 @@ SOURCE_FILE@[0; 38) NAME_REF@[8; 13) IDENT@[8; 13) "Clone" R_ANGLE@[13; 14) ">" - err: `expected trait or type` - err: `expected `{`` WHITESPACE@[14; 15) "\n" IMPL_BLOCK@[15; 37) IMPL_KW@[15; 19) "impl" @@ -47,3 +45,5 @@ SOURCE_FILE@[0; 38) L_CURLY@[35; 36) "{" R_CURLY@[36; 37) "}" WHITESPACE@[37; 38) "\n" +err: `expected trait or type` +err: `expected `{`` diff --git a/crates/ra_syntax/tests/data/parser/err/0027_incomplere_where_for.txt b/crates/ra_syntax/tests/data/parser/err/0027_incomplere_where_for.txt index c87c2c936..5a2b52d05 100644 --- a/crates/ra_syntax/tests/data/parser/err/0027_incomplere_where_for.txt +++ b/crates/ra_syntax/tests/data/parser/err/0027_incomplere_where_for.txt @@ -19,10 +19,10 @@ SOURCE_FILE@[0; 30) LIFETIME_PARAM@[23; 25) LIFETIME@[23; 25) "\'a" R_ANGLE@[25; 26) ">" - err: `expected a path` - err: `expected colon` WHITESPACE@[26; 27) "\n" BLOCK@[27; 29) L_CURLY@[27; 28) "{" R_CURLY@[28; 29) "}" WHITESPACE@[29; 30) "\n" +err: `expected a path` +err: `expected colon` diff --git a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt index 97ec4a5ab..8a59a5ac3 100644 --- a/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt +++ b/crates/ra_syntax/tests/data/parser/err/0028_macro_2.0.txt @@ -4,7 +4,6 @@ SOURCE_FILE@[0; 349) PATH_SEGMENT@[0; 5) NAME_REF@[0; 5) IDENT@[0; 5) "macro" - err: `expected EXCL` WHITESPACE@[5; 6) " " NAME@[6; 21) IDENT@[6; 21) "parse_use_trees" @@ -28,9 +27,7 @@ SOURCE_FILE@[0; 349) R_PAREN@[38; 39) ")" STAR@[39; 40) "*" R_PAREN@[40; 41) ")" - err: `expected SEMI` WHITESPACE@[41; 42) " " - err: `expected an item` ERROR@[42; 93) L_CURLY@[42; 43) "{" WHITESPACE@[43; 48) "\n " @@ -85,7 +82,6 @@ SOURCE_FILE@[0; 349) PATH_SEGMENT@[134; 139) NAME_REF@[134; 139) IDENT@[134; 139) "macro" - err: `expected SEMI` WHITESPACE@[139; 140) " " EXPR_STMT@[140; 154) CALL_EXPR@[140; 154) @@ -98,175 +94,112 @@ SOURCE_FILE@[0; 349) L_PAREN@[150; 151) "(" ARRAY_EXPR@[151; 154) L_BRACK@[151; 152) "[" - err: `expected expression` ERROR@[152; 153) DOLLAR@[152; 153) "$" - err: `expected COMMA` PAREN_EXPR@[153; 154) L_PAREN@[153; 154) "(" - err: `expected expression` - err: `expected R_PAREN` - err: `expected COMMA` - err: `expected expression` - err: `expected R_BRACK` - err: `expected COMMA` - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[154; 155) ERROR@[154; 155) DOLLAR@[154; 155) "$" - err: `expected SEMI` EXPR_STMT@[155; 160) PATH_EXPR@[155; 160) PATH@[155; 160) PATH_SEGMENT@[155; 160) NAME_REF@[155; 160) IDENT@[155; 160) "input" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[160; 161) ERROR@[160; 161) COLON@[160; 161) ":" - err: `expected SEMI` EXPR_STMT@[161; 165) PATH_EXPR@[161; 165) PATH@[161; 165) PATH_SEGMENT@[161; 165) NAME_REF@[161; 165) IDENT@[161; 165) "expr" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[165; 166) ERROR@[165; 166) R_PAREN@[165; 166) ")" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[166; 167) ERROR@[166; 167) COMMA@[166; 167) "," - err: `expected SEMI` EXPR_STMT@[167; 170) PREFIX_EXPR@[167; 170) STAR@[167; 168) "*" WHITESPACE@[168; 169) " " - err: `expected expression` ERROR@[169; 170) DOLLAR@[169; 170) "$" - err: `expected SEMI` EXPR_STMT@[170; 171) PAREN_EXPR@[170; 171) L_PAREN@[170; 171) "(" - err: `expected expression` - err: `expected R_PAREN` - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[171; 172) ERROR@[171; 172) COMMA@[171; 172) "," - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[172; 173) ERROR@[172; 173) R_PAREN@[172; 173) ")" - err: `expected SEMI` EXPR_STMT@[173; 175) PREFIX_EXPR@[173; 175) STAR@[173; 174) "*" - err: `expected expression` ERROR@[174; 175) R_BRACK@[174; 175) "]" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[175; 176) ERROR@[175; 176) COMMA@[175; 176) "," - err: `expected SEMI` WHITESPACE@[176; 177) " " EXPR_STMT@[177; 180) ARRAY_EXPR@[177; 180) L_BRACK@[177; 178) "[" - err: `expected expression` ERROR@[178; 179) DOLLAR@[178; 179) "$" - err: `expected COMMA` PAREN_EXPR@[179; 180) L_PAREN@[179; 180) "(" - err: `expected expression` - err: `expected R_PAREN` - err: `expected COMMA` - err: `expected expression` - err: `expected R_BRACK` - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[180; 181) ERROR@[180; 181) DOLLAR@[180; 181) "$" - err: `expected SEMI` EXPR_STMT@[181; 187) PATH_EXPR@[181; 187) PATH@[181; 187) PATH_SEGMENT@[181; 187) NAME_REF@[181; 187) IDENT@[181; 187) "output" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[187; 188) ERROR@[187; 188) COLON@[187; 188) ":" - err: `expected SEMI` EXPR_STMT@[188; 192) PATH_EXPR@[188; 192) PATH@[188; 192) PATH_SEGMENT@[188; 192) NAME_REF@[188; 192) IDENT@[188; 192) "expr" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[192; 193) ERROR@[192; 193) R_PAREN@[192; 193) ")" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[193; 194) ERROR@[193; 194) COMMA@[193; 194) "," - err: `expected SEMI` EXPR_STMT@[194; 197) PREFIX_EXPR@[194; 197) STAR@[194; 195) "*" WHITESPACE@[195; 196) " " - err: `expected expression` ERROR@[196; 197) DOLLAR@[196; 197) "$" - err: `expected SEMI` EXPR_STMT@[197; 198) PAREN_EXPR@[197; 198) L_PAREN@[197; 198) "(" - err: `expected expression` - err: `expected R_PAREN` - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[198; 199) ERROR@[198; 199) COMMA@[198; 199) "," - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[199; 200) ERROR@[199; 200) R_PAREN@[199; 200) ")" - err: `expected SEMI` EXPR_STMT@[200; 202) PREFIX_EXPR@[200; 202) STAR@[200; 201) "*" - err: `expected expression` ERROR@[201; 202) R_BRACK@[201; 202) "]" - err: `expected SEMI` - err: `expected expression` EXPR_STMT@[202; 203) ERROR@[202; 203) R_PAREN@[202; 203) ")" - err: `expected SEMI` WHITESPACE@[203; 204) " " BLOCK_EXPR@[204; 346) BLOCK@[204; 346) @@ -323,3 +256,70 @@ SOURCE_FILE@[0; 349) WHITESPACE@[346; 347) "\n" R_CURLY@[347; 348) "}" WHITESPACE@[348; 349) "\n" +err: `expected EXCL` +err: `expected SEMI` +err: `expected an item` +err: `expected SEMI` +err: `expected expression` +err: `expected COMMA` +err: `expected expression` +err: `expected R_PAREN` +err: `expected COMMA` +err: `expected expression` +err: `expected R_BRACK` +err: `expected COMMA` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected R_PAREN` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected COMMA` +err: `expected expression` +err: `expected R_PAREN` +err: `expected COMMA` +err: `expected expression` +err: `expected R_BRACK` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected R_PAREN` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` +err: `expected expression` +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/err/0029_field_completion.txt b/crates/ra_syntax/tests/data/parser/err/0029_field_completion.txt index 27a0884f9..fa92f0845 100644 --- a/crates/ra_syntax/tests/data/parser/err/0029_field_completion.txt +++ b/crates/ra_syntax/tests/data/parser/err/0029_field_completion.txt @@ -29,7 +29,7 @@ SOURCE_FILE@[0; 24) NAME_REF@[19; 20) IDENT@[19; 20) "a" DOT@[20; 21) "." - err: `expected field name or number` WHITESPACE@[21; 22) "\n" R_CURLY@[22; 23) "}" WHITESPACE@[23; 24) "\n" +err: `expected field name or number` diff --git a/crates/ra_syntax/tests/data/parser/err/0030_string_suffixes.txt b/crates/ra_syntax/tests/data/parser/err/0030_string_suffixes.txt index e0e38d37d..fb6d3c9c7 100644 --- a/crates/ra_syntax/tests/data/parser/err/0030_string_suffixes.txt +++ b/crates/ra_syntax/tests/data/parser/err/0030_string_suffixes.txt @@ -21,7 +21,6 @@ SOURCE_FILE@[0; 112) WHITESPACE@[23; 24) " " LITERAL@[24; 27) CHAR@[24; 27) "\'c\'" - err: `expected SEMI` EXPR_STMT@[27; 31) PATH_EXPR@[27; 30) PATH@[27; 30) @@ -68,3 +67,4 @@ SOURCE_FILE@[0; 112) WHITESPACE@[109; 110) "\n" R_CURLY@[110; 111) "}" WHITESPACE@[111; 112) "\n" +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt index 80a973d4d..b4ec999b1 100644 --- a/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt @@ -24,7 +24,6 @@ SOURCE_FILE@[0; 350) BLOCK@[29; 128) L_CURLY@[29; 30) "{" WHITESPACE@[30; 39) "\n " - err: `A block in this position cannot accept inner attributes` ATTR@[39; 83) POUND@[39; 40) "#" EXCL@[40; 41) "!" @@ -53,7 +52,6 @@ SOURCE_FILE@[0; 350) BLOCK@[142; 257) L_CURLY@[142; 143) "{" WHITESPACE@[143; 152) "\n " - err: `A block in this position cannot accept inner attributes` ATTR@[152; 171) POUND@[152; 153) "#" EXCL@[153; 154) "!" @@ -66,7 +64,6 @@ SOURCE_FILE@[0; 350) R_PAREN@[169; 170) ")" R_BRACK@[170; 171) "]" WHITESPACE@[171; 180) "\n " - err: `A block in this position cannot accept inner attributes` ATTR@[180; 212) POUND@[180; 181) "#" EXCL@[181; 182) "!" @@ -93,7 +90,6 @@ SOURCE_FILE@[0; 350) BLOCK@[273; 347) L_CURLY@[273; 274) "{" WHITESPACE@[274; 283) "\n " - err: `A block in this position cannot accept inner attributes` ATTR@[283; 302) POUND@[283; 284) "#" EXCL@[284; 285) "!" @@ -112,3 +108,7 @@ SOURCE_FILE@[0; 350) WHITESPACE@[347; 348) "\n" R_CURLY@[348; 349) "}" WHITESPACE@[349; 350) "\n" +err: `A block in this position cannot accept inner attributes` +err: `A block in this position cannot accept inner attributes` +err: `A block in this position cannot accept inner attributes` +err: `A block in this position cannot accept inner attributes` diff --git a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt index 92e3a1ee8..a3c53f353 100644 --- a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt @@ -36,11 +36,8 @@ SOURCE_FILE@[0; 293) MATCH_ARM@[51; 78) ATTR@[51; 52) POUND@[51; 52) "#" - err: `expected `[`` - err: `expected pattern` ERROR@[52; 53) EXCL@[52; 53) "!" - err: `expected FAT_ARROW` ARRAY_EXPR@[53; 78) L_BRACK@[53; 54) "[" CALL_EXPR@[54; 77) @@ -55,7 +52,6 @@ SOURCE_FILE@[0; 293) STRING@[58; 76) "\"Not allowed here\"" R_PAREN@[76; 77) ")" R_BRACK@[77; 78) "]" - err: `expected COMMA` WHITESPACE@[78; 87) "\n " MATCH_ARM@[87; 94) PLACEHOLDER_PAT@[87; 88) @@ -106,11 +102,8 @@ SOURCE_FILE@[0; 293) MATCH_ARM@[160; 179) ATTR@[160; 161) POUND@[160; 161) "#" - err: `expected `[`` - err: `expected pattern` ERROR@[161; 162) EXCL@[161; 162) "!" - err: `expected FAT_ARROW` ARRAY_EXPR@[162; 179) L_BRACK@[162; 163) "[" CALL_EXPR@[163; 178) @@ -152,11 +145,8 @@ SOURCE_FILE@[0; 293) WHITESPACE@[222; 231) "\n " ATTR@[231; 232) POUND@[231; 232) "#" - err: `expected `[`` - err: `expected pattern` ERROR@[232; 233) EXCL@[232; 233) "!" - err: `expected FAT_ARROW` ARRAY_EXPR@[233; 250) L_BRACK@[233; 234) "[" CALL_EXPR@[234; 249) @@ -171,7 +161,6 @@ SOURCE_FILE@[0; 293) STRING@[238; 248) "\"Nor here\"" R_PAREN@[248; 249) ")" R_BRACK@[249; 250) "]" - err: `expected COMMA` WHITESPACE@[250; 259) "\n " MATCH_ARM@[259; 266) PLACEHOLDER_PAT@[259; 260) @@ -199,3 +188,14 @@ SOURCE_FILE@[0; 293) WHITESPACE@[290; 291) "\n" R_CURLY@[291; 292) "}" WHITESPACE@[292; 293) "\n" +err: `expected `[`` +err: `expected pattern` +err: `expected FAT_ARROW` +err: `expected COMMA` +err: `expected `[`` +err: `expected pattern` +err: `expected FAT_ARROW` +err: `expected `[`` +err: `expected pattern` +err: `expected FAT_ARROW` +err: `expected COMMA` diff --git a/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt index ac9cb63f7..7bcf5ec81 100644 --- a/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt +++ b/crates/ra_syntax/tests/data/parser/err/0033_match_arms_outer_attrs.txt @@ -54,11 +54,11 @@ SOURCE_FILE@[0; 89) IDENT@[74; 78) "test" R_PAREN@[78; 79) ")" R_BRACK@[79; 80) "]" - err: `expected pattern` - err: `expected FAT_ARROW` - err: `expected expression` WHITESPACE@[80; 85) "\n " R_CURLY@[85; 86) "}" WHITESPACE@[86; 87) "\n" R_CURLY@[87; 88) "}" WHITESPACE@[88; 89) "\n" +err: `expected pattern` +err: `expected FAT_ARROW` +err: `expected expression` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0001_array_type_missing_semi.txt b/crates/ra_syntax/tests/data/parser/inline/err/0001_array_type_missing_semi.txt index 3020f9086..eb6d98fcd 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0001_array_type_missing_semi.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0001_array_type_missing_semi.txt @@ -12,16 +12,16 @@ SOURCE_FILE@[0; 18) TUPLE_TYPE@[10; 12) L_PAREN@[10; 11) "(" R_PAREN@[11; 12) ")" - err: `expected `;` or `]`` - err: `expected SEMI` WHITESPACE@[12; 13) " " - err: `expected an item` ERROR@[13; 15) INT_NUMBER@[13; 15) "92" - err: `expected an item` ERROR@[15; 16) R_BRACK@[15; 16) "]" - err: `expected an item` ERROR@[16; 17) SEMI@[16; 17) ";" WHITESPACE@[17; 18) "\n" +err: `expected `;` or `]`` +err: `expected SEMI` +err: `expected an item` +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0002_misplaced_label_err.txt b/crates/ra_syntax/tests/data/parser/inline/err/0002_misplaced_label_err.txt index d61d8e73e..b1d104bd4 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0002_misplaced_label_err.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0002_misplaced_label_err.txt @@ -16,13 +16,13 @@ SOURCE_FILE@[0; 30) LABEL@[16; 22) LIFETIME@[16; 21) "\'loop" COLON@[21; 22) ":" - err: `expected a loop` - err: `expected SEMI` WHITESPACE@[22; 23) " " IMPL_BLOCK@[23; 27) IMPL_KW@[23; 27) "impl" - err: `expected type` - err: `expected `{`` WHITESPACE@[27; 28) "\n" R_CURLY@[28; 29) "}" WHITESPACE@[29; 30) "\n" +err: `expected a loop` +err: `expected SEMI` +err: `expected type` +err: `expected `{`` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0003_pointer_type_no_mutability.txt b/crates/ra_syntax/tests/data/parser/inline/err/0003_pointer_type_no_mutability.txt index 3d7a6a745..b470d9ad1 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0003_pointer_type_no_mutability.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0003_pointer_type_no_mutability.txt @@ -9,9 +9,9 @@ SOURCE_FILE@[0; 14) WHITESPACE@[8; 9) " " POINTER_TYPE@[9; 12) STAR@[9; 10) "*" - err: `expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)` TUPLE_TYPE@[10; 12) L_PAREN@[10; 11) "(" R_PAREN@[11; 12) ")" SEMI@[12; 13) ";" WHITESPACE@[13; 14) "\n" +err: `expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0004_impl_type.txt b/crates/ra_syntax/tests/data/parser/inline/err/0004_impl_type.txt index 86f84459a..ef4e0d5dd 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0004_impl_type.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0004_impl_type.txt @@ -35,8 +35,6 @@ SOURCE_FILE@[0; 87) WHITESPACE@[33; 34) "\n" IMPL_BLOCK@[34; 38) IMPL_KW@[34; 38) "impl" - err: `expected trait or type` - err: `expected `{`` WHITESPACE@[38; 39) " " IMPL_BLOCK@[39; 54) IMPL_KW@[39; 43) "impl" @@ -61,8 +59,6 @@ SOURCE_FILE@[0; 87) IDENT@[60; 66) "Trait2" WHITESPACE@[66; 67) " " FOR_KW@[67; 70) "for" - err: `expected trait or type` - err: `expected `{`` WHITESPACE@[70; 71) " " IMPL_BLOCK@[71; 86) IMPL_KW@[71; 75) "impl" @@ -77,3 +73,7 @@ SOURCE_FILE@[0; 87) L_CURLY@[84; 85) "{" R_CURLY@[85; 86) "}" WHITESPACE@[86; 87) "\n" +err: `expected trait or type` +err: `expected `{`` +err: `expected trait or type` +err: `expected `{`` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0005_fn_pointer_type_missing_fn.txt b/crates/ra_syntax/tests/data/parser/inline/err/0005_fn_pointer_type_missing_fn.txt index 4587525aa..41e623b41 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0005_fn_pointer_type_missing_fn.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0005_fn_pointer_type_missing_fn.txt @@ -8,16 +8,16 @@ SOURCE_FILE@[0; 20) EQ@[7; 8) "=" WHITESPACE@[8; 9) " " UNSAFE_KW@[9; 15) "unsafe" - err: `expected `fn`` - err: `expected SEMI` WHITESPACE@[15; 16) " " - err: `expected an item` ERROR@[16; 17) L_PAREN@[16; 17) "(" - err: `expected an item` ERROR@[17; 18) R_PAREN@[17; 18) ")" - err: `expected an item` ERROR@[18; 19) SEMI@[18; 19) ";" WHITESPACE@[19; 20) "\n" +err: `expected `fn`` +err: `expected SEMI` +err: `expected an item` +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0006_unsafe_block_in_mod.txt b/crates/ra_syntax/tests/data/parser/inline/err/0006_unsafe_block_in_mod.txt index fefa35c20..f1d0dd5c6 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0006_unsafe_block_in_mod.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0006_unsafe_block_in_mod.txt @@ -11,11 +11,9 @@ SOURCE_FILE@[0; 33) L_CURLY@[8; 9) "{" R_CURLY@[9; 10) "}" WHITESPACE@[10; 11) " " - err: `expected an item` ERROR@[11; 17) UNSAFE_KW@[11; 17) "unsafe" WHITESPACE@[17; 18) " " - err: `expected an item` ERROR@[18; 21) L_CURLY@[18; 19) "{" WHITESPACE@[19; 20) " " @@ -33,3 +31,5 @@ SOURCE_FILE@[0; 33) L_CURLY@[30; 31) "{" R_CURLY@[31; 32) "}" WHITESPACE@[32; 33) "\n" +err: `expected an item` +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0007_async_without_semicolon.txt b/crates/ra_syntax/tests/data/parser/inline/err/0007_async_without_semicolon.txt index 8afcd5429..1a8fa029c 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0007_async_without_semicolon.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0007_async_without_semicolon.txt @@ -25,7 +25,7 @@ SOURCE_FILE@[0; 30) BLOCK@[25; 27) L_CURLY@[25; 26) "{" R_CURLY@[26; 27) "}" - err: `expected SEMI` WHITESPACE@[27; 28) " " R_CURLY@[28; 29) "}" WHITESPACE@[29; 30) "\n" +err: `expected SEMI` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0008_pub_expr.txt b/crates/ra_syntax/tests/data/parser/inline/err/0008_pub_expr.txt index 1af31c48b..cadbbc078 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0008_pub_expr.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0008_pub_expr.txt @@ -14,7 +14,6 @@ SOURCE_FILE@[0; 21) ERROR@[11; 14) VISIBILITY@[11; 14) PUB_KW@[11; 14) "pub" - err: `expected an item` WHITESPACE@[14; 15) " " EXPR_STMT@[15; 18) LITERAL@[15; 17) @@ -23,3 +22,4 @@ SOURCE_FILE@[0; 21) WHITESPACE@[18; 19) " " R_CURLY@[19; 20) "}" WHITESPACE@[20; 21) "\n" +err: `expected an item` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0009_attr_on_expr_not_allowed.txt b/crates/ra_syntax/tests/data/parser/inline/err/0009_attr_on_expr_not_allowed.txt index 9d50a520f..8e7d7d241 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0009_attr_on_expr_not_allowed.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0009_attr_on_expr_not_allowed.txt @@ -27,7 +27,6 @@ SOURCE_FILE@[0; 48) WHITESPACE@[22; 23) " " LITERAL@[23; 24) INT_NUMBER@[23; 24) "2" - err: `attributes are not allowed on BIN_EXPR` SEMI@[24; 25) ";" WHITESPACE@[25; 29) "\n " EXPR_STMT@[29; 45) @@ -48,8 +47,9 @@ SOURCE_FILE@[0; 48) BLOCK@[42; 44) L_CURLY@[42; 43) "{" R_CURLY@[43; 44) "}" - err: `attributes are not allowed on IF_EXPR` SEMI@[44; 45) ";" WHITESPACE@[45; 46) "\n" R_CURLY@[46; 47) "}" WHITESPACE@[47; 48) "\n" +err: `attributes are not allowed on BIN_EXPR` +err: `attributes are not allowed on IF_EXPR` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0010_bad_tuple_index_expr.txt b/crates/ra_syntax/tests/data/parser/inline/err/0010_bad_tuple_index_expr.txt index c111f60ea..36717439e 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0010_bad_tuple_index_expr.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0010_bad_tuple_index_expr.txt @@ -19,7 +19,6 @@ SOURCE_FILE@[0; 47) NAME_REF@[15; 16) IDENT@[15; 16) "x" DOT@[16; 17) "." - err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` FLOAT_NUMBER@[17; 19) "0." SEMI@[19; 20) ";" WHITESPACE@[20; 25) "\n " @@ -31,7 +30,6 @@ SOURCE_FILE@[0; 47) NAME_REF@[25; 26) IDENT@[25; 26) "x" DOT@[26; 27) "." - err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` INT_NUMBER@[27; 31) "1i32" SEMI@[31; 32) ";" WHITESPACE@[32; 37) "\n " @@ -43,9 +41,11 @@ SOURCE_FILE@[0; 47) NAME_REF@[37; 38) IDENT@[37; 38) "x" DOT@[38; 39) "." - err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` INT_NUMBER@[39; 43) "0x01" SEMI@[43; 44) ";" WHITESPACE@[44; 45) "\n" R_CURLY@[45; 46) "}" WHITESPACE@[46; 47) "\n" +err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` +err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` +err: `Tuple (struct) field access is only allowed through decimal integers with no underscores or suffix` diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt index 220191ffa..5f39e7238 100644 --- a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt +++ b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt @@ -1,7 +1,6 @@ SOURCE_FILE@[0; 50) ERROR@[0; 5) ASYNC_KW@[0; 5) "async" - err: `expected fn, trait or impl` WHITESPACE@[5; 6) " " FN_DEF@[6; 24) UNSAFE_KW@[6; 12) "unsafe" @@ -20,7 +19,6 @@ SOURCE_FILE@[0; 50) WHITESPACE@[24; 25) "\n" ERROR@[25; 31) UNSAFE_KW@[25; 31) "unsafe" - err: `expected fn, trait or impl` WHITESPACE@[31; 32) " " FN_DEF@[32; 49) CONST_KW@[32; 37) "const" @@ -37,3 +35,5 @@ SOURCE_FILE@[0; 50) L_CURLY@[47; 48) "{" R_CURLY@[48; 49) "}" WHITESPACE@[49; 50) "\n" +err: `expected fn, trait or impl` +err: `expected fn, trait or impl` -- cgit v1.2.3 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/ast.rs | 16 ++++++--- crates/ra_syntax/src/fuzz.rs | 21 ++++++------ crates/ra_syntax/src/lib.rs | 55 ++++++++++++++----------------- crates/ra_syntax/src/parsing/reparsing.rs | 4 +-- crates/ra_syntax/src/ptr.rs | 2 +- crates/ra_syntax/src/syntax_node.rs | 10 ------ crates/ra_syntax/tests/test.rs | 8 ++--- 7 files changed, 54 insertions(+), 62 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index f7e33366e..319110b6a 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -80,7 +80,9 @@ fn test_doc_comment_none() { // non-doc mod foo {} "#, - ); + ) + .ok() + .unwrap(); let module = file.syntax().descendants().find_map(Module::cast).unwrap(); assert!(module.doc_comment_text().is_none()); } @@ -93,7 +95,9 @@ fn test_doc_comment_of_items() { // non-doc mod foo {} "#, - ); + ) + .ok() + .unwrap(); let module = file.syntax().descendants().find_map(Module::cast).unwrap(); assert_eq!("doc", module.doc_comment_text().unwrap()); } @@ -110,7 +114,9 @@ fn test_doc_comment_preserves_indents() { /// ``` mod foo {} "#, - ); + ) + .ok() + .unwrap(); let module = file.syntax().descendants().find_map(Module::cast).unwrap(); assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap()); } @@ -133,7 +139,9 @@ where for<'a> F: Fn(&'a str) {} "#, - ); + ) + .ok() + .unwrap(); let where_clause = file.syntax().descendants().find_map(WhereClause::cast).unwrap(); let mut predicates = where_clause.predicates(); diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs index af11b2e1a..6a9905bd1 100644 --- a/crates/ra_syntax/src/fuzz.rs +++ b/crates/ra_syntax/src/fuzz.rs @@ -5,12 +5,11 @@ use std::str::{self, FromStr}; fn check_file_invariants(file: &SourceFile) { let root = file.syntax(); validation::validate_block_structure(root); - let _ = file.errors(); } pub fn check_parser(text: &str) { let file = SourceFile::parse(text); - check_file_invariants(&file); + check_file_invariants(&file.tree); } #[derive(Debug, Clone)] @@ -44,16 +43,18 @@ impl CheckReparse { } pub fn run(&self) { - let file = SourceFile::parse(&self.text); - let new_file = file.reparse(&self.edit); - check_file_invariants(&new_file); - assert_eq!(&new_file.syntax().text().to_string(), &self.edited_text); + let parse = SourceFile::parse(&self.text); + let new_parse = parse.reparse(&self.edit); + check_file_invariants(&new_parse.tree); + assert_eq!(&new_parse.tree.syntax().text().to_string(), &self.edited_text); let full_reparse = SourceFile::parse(&self.edited_text); - for (a, b) in new_file.syntax().descendants().zip(full_reparse.syntax().descendants()) { + for (a, b) in + new_parse.tree.syntax().descendants().zip(full_reparse.tree.syntax().descendants()) + { if (a.kind(), a.range()) != (b.kind(), b.range()) { - eprint!("original:\n{}", file.syntax().debug_dump()); - eprint!("reparsed:\n{}", new_file.syntax().debug_dump()); - eprint!("full reparse:\n{}", full_reparse.syntax().debug_dump()); + eprint!("original:\n{}", parse.tree.syntax().debug_dump()); + eprint!("reparsed:\n{}", new_parse.tree.syntax().debug_dump()); + eprint!("full reparse:\n{}", full_reparse.tree.syntax().debug_dump()); assert_eq!( format!("{:?}", a), format!("{:?}", b), 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; diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index dc913cf2b..cf27a3393 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -178,12 +178,12 @@ mod tests { let edit = AtomTextEdit::replace(range, replace_with.to_owned()); let after = edit.apply(before.clone()); - let fully_reparsed = SourceFile::parse2(&after); + let fully_reparsed = SourceFile::parse(&after); let incrementally_reparsed = { let f = SourceFile::parse(&before); let edit = AtomTextEdit { delete: range, insert: replace_with.to_string() }; let (green, new_errors, range) = - incremental_reparse(f.syntax(), &edit, f.errors()).unwrap(); + incremental_reparse(f.tree.syntax(), &edit, f.errors.to_vec()).unwrap(); assert_eq!(range.len(), reparsed_len.into(), "reparsed fragment has wrong length"); Parse { tree: SourceFile::new(green), errors: Arc::new(new_errors) } }; diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index cee9503ca..10cddb852 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -76,7 +76,7 @@ impl From> for SyntaxNodePtr { fn test_local_syntax_ptr() { use crate::{ast, AstNode, SourceFile}; - let file = SourceFile::parse("struct Foo { f: u32, }"); + let file = SourceFile::parse("struct Foo { f: u32, }").ok().unwrap(); let field = file.syntax().descendants().find_map(ast::NamedFieldDef::cast).unwrap(); let ptr = SyntaxNodePtr::new(field.syntax()); let field_syntax = ptr.to_node(file.syntax()); diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 769125d11..4105b5220 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -280,16 +280,6 @@ impl SyntaxNode { buf } - pub(crate) fn root_data(&self) -> &[SyntaxError] { - match self.0.root_data() { - None => &[], - Some(data) => { - let data: &Vec = std::any::Any::downcast_ref(data).unwrap(); - data.as_slice() - } - } - } - pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { self.0.replace_with(replacement) } diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 4b711f271..f31e12588 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -21,7 +21,7 @@ fn lexer_tests() { #[test] fn parser_tests() { dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], |text, path| { - let parse = SourceFile::parse2(text); + let parse = SourceFile::parse(text); let errors = parse.errors.as_slice(); assert_eq!( errors, @@ -32,7 +32,7 @@ fn parser_tests() { parse.debug_dump() }); dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], |text, path| { - let parse = SourceFile::parse2(text); + let parse = SourceFile::parse(text); let errors = parse.errors.as_slice(); assert!(!errors.is_empty(), "There should be errors in the file {:?}", path.display()); parse.debug_dump() @@ -78,9 +78,7 @@ fn self_hosting_parsing() { { count += 1; let text = read_text(entry.path()); - let node = SourceFile::parse(&text); - let errors = node.errors(); - assert_eq!(&*errors, &[], "There should be no errors in the file {:?}", entry); + SourceFile::parse(&text).ok().expect("There should be no errors in the file"); } assert!( count > 30, -- cgit v1.2.3