From 55f15641011b5d1211d6f86ce77a60f05b02a25b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 27 Dec 2021 21:34:39 +0300 Subject: [PATCH] remove fragments from syntax --- crates/syntax/src/lib.rs | 7 ---- crates/syntax/src/tests.rs | 36 ------------------- .../item/err/0000_extra_keyword.rast | 1 - .../fragments/item/err/0000_extra_keyword.rs | 1 - .../parser/fragments/item/ok/0000_fn.rast | 13 ------- .../parser/fragments/item/ok/0000_fn.rs | 1 - .../path/err/0000_reserved_word.rast | 1 - .../fragments/path/err/0000_reserved_word.rs | 1 - .../fragments/path/err/0001_expression.rast | 1 - .../fragments/path/err/0001_expression.rs | 1 - .../fragments/path/ok/0000_single_ident.rast | 4 --- .../fragments/path/ok/0000_single_ident.rs | 1 - .../fragments/path/ok/0001_multipart.rast | 14 -------- .../fragments/path/ok/0001_multipart.rs | 1 - .../pattern/err/0000_reserved_word.rast | 1 - .../pattern/err/0000_reserved_word.rs | 1 - .../pattern/err/0001_missing_paren.rast | 1 - .../pattern/err/0001_missing_paren.rs | 1 - .../fragments/pattern/ok/0000_enum.rast | 10 ------ .../parser/fragments/pattern/ok/0000_enum.rs | 1 - 20 files changed, 98 deletions(-) delete mode 100644 crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rast delete mode 100644 crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rs delete mode 100644 crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rast delete mode 100644 crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rs delete mode 100644 crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rast delete mode 100644 crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rs delete mode 100644 crates/syntax/test_data/parser/fragments/path/err/0001_expression.rast delete mode 100644 crates/syntax/test_data/parser/fragments/path/err/0001_expression.rs delete mode 100644 crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rast delete mode 100644 crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rs delete mode 100644 crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rast delete mode 100644 crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rs delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rast delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rs delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rast delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rs delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast delete mode 100644 crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rs diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 912bf4d1da..63a14ec913 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -180,13 +180,6 @@ impl ast::Path { } } -impl ast::Pat { - /// Returns `text`, parsed as a pattern, but only if it has no errors. - pub fn parse(text: &str) -> Result { - parsing::parse_text_as(text, parser::ParserEntryPoint::Pattern) - } -} - impl ast::Expr { /// Returns `text`, parsed as an expression, but only if it has no errors. pub fn parse(text: &str) -> Result { diff --git a/crates/syntax/src/tests.rs b/crates/syntax/src/tests.rs index 58c4b5b8fc..0611143e2a 100644 --- a/crates/syntax/src/tests.rs +++ b/crates/syntax/src/tests.rs @@ -59,24 +59,6 @@ fn validation_tests() { }); } -#[test] -fn path_parser_tests() { - fragment_parser_dir_test( - &["parser/fragments/path/ok"], - &["parser/fragments/path/err"], - crate::ast::Path::parse, - ); -} - -#[test] -fn pattern_parser_tests() { - fragment_parser_dir_test( - &["parser/fragments/pattern/ok"], - &["parser/fragments/pattern/err"], - crate::ast::Pat::parse, - ); -} - #[test] fn parser_fuzz_tests() { for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) { @@ -136,24 +118,6 @@ fn assert_errors_are_present(errors: &[SyntaxError], path: &Path) { assert!(!errors.is_empty(), "There should be errors in the file {:?}", path.display()); } -fn fragment_parser_dir_test(ok_paths: &[&str], err_paths: &[&str], f: F) -where - T: crate::AstNode, - F: Fn(&str) -> Result, -{ - dir_tests(&test_data_dir(), ok_paths, "rast", |text, path| match f(text) { - Ok(node) => format!("{:#?}", crate::ast::AstNode::syntax(&node)), - Err(_) => panic!("Failed to parse '{:?}'", path), - }); - dir_tests(&test_data_dir(), err_paths, "rast", |text, path| { - if f(text).is_ok() { - panic!("'{:?}' successfully parsed when it should have errored", path); - } else { - "ERROR\n".to_owned() - } - }); -} - /// Calls callback `f` with input code and file paths for each `.rs` file in `test_data_dir` /// subdirectories defined by `paths`. /// diff --git a/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rast b/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rast deleted file mode 100644 index 5df7507e2d..0000000000 --- a/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rast +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rs b/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rs deleted file mode 100644 index dc32389bbb..0000000000 --- a/crates/syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rs +++ /dev/null @@ -1 +0,0 @@ -fn fn foo() {} diff --git a/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rast b/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rast deleted file mode 100644 index 4ff9967bea..0000000000 --- a/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rast +++ /dev/null @@ -1,13 +0,0 @@ -FN@0..11 - FN_KW@0..2 "fn" - WHITESPACE@2..3 " " - NAME@3..6 - IDENT@3..6 "foo" - PARAM_LIST@6..8 - L_PAREN@6..7 "(" - R_PAREN@7..8 ")" - WHITESPACE@8..9 " " - BLOCK_EXPR@9..11 - STMT_LIST@9..11 - L_CURLY@9..10 "{" - R_CURLY@10..11 "}" diff --git a/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rs b/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rs deleted file mode 100644 index 8f3b7ef112..0000000000 --- a/crates/syntax/test_data/parser/fragments/item/ok/0000_fn.rs +++ /dev/null @@ -1 +0,0 @@ -fn foo() {} diff --git a/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rast b/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rast deleted file mode 100644 index 5df7507e2d..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rast +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rs b/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rs deleted file mode 100644 index 2046de0492..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/err/0000_reserved_word.rs +++ /dev/null @@ -1 +0,0 @@ -struct diff --git a/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rast b/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rast deleted file mode 100644 index 5df7507e2d..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rast +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rs b/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rs deleted file mode 100644 index 745e8d376f..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/err/0001_expression.rs +++ /dev/null @@ -1 +0,0 @@ -a + b diff --git a/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rast b/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rast deleted file mode 100644 index 0c5d4360fa..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rast +++ /dev/null @@ -1,4 +0,0 @@ -PATH@0..3 - PATH_SEGMENT@0..3 - NAME_REF@0..3 - IDENT@0..3 "foo" diff --git a/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rs b/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rs deleted file mode 100644 index 257cc5642c..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/ok/0000_single_ident.rs +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rast b/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rast deleted file mode 100644 index 4a2b45e6a9..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rast +++ /dev/null @@ -1,14 +0,0 @@ -PATH@0..13 - PATH@0..8 - PATH@0..3 - PATH_SEGMENT@0..3 - NAME_REF@0..3 - IDENT@0..3 "foo" - COLON2@3..5 "::" - PATH_SEGMENT@5..8 - NAME_REF@5..8 - IDENT@5..8 "bar" - COLON2@8..10 "::" - PATH_SEGMENT@10..13 - NAME_REF@10..13 - IDENT@10..13 "baz" diff --git a/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rs b/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rs deleted file mode 100644 index 81e0b21cd4..0000000000 --- a/crates/syntax/test_data/parser/fragments/path/ok/0001_multipart.rs +++ /dev/null @@ -1 +0,0 @@ -foo::bar::baz diff --git a/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rast b/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rast deleted file mode 100644 index 5df7507e2d..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rast +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rs b/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rs deleted file mode 100644 index ae26fc4556..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rs +++ /dev/null @@ -1 +0,0 @@ -fn diff --git a/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rast b/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rast deleted file mode 100644 index 5df7507e2d..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rast +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rs b/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rs deleted file mode 100644 index 61a391d084..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rs +++ /dev/null @@ -1 +0,0 @@ -Some(x diff --git a/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast b/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast deleted file mode 100644 index dcf102339a..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast +++ /dev/null @@ -1,10 +0,0 @@ -TUPLE_STRUCT_PAT@0..7 - PATH@0..4 - PATH_SEGMENT@0..4 - NAME_REF@0..4 - IDENT@0..4 "Some" - L_PAREN@4..5 "(" - IDENT_PAT@5..6 - NAME@5..6 - IDENT@5..6 "x" - R_PAREN@6..7 ")" diff --git a/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rs b/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rs deleted file mode 100644 index 87114dd788..0000000000 --- a/crates/syntax/test_data/parser/fragments/pattern/ok/0000_enum.rs +++ /dev/null @@ -1 +0,0 @@ -Some(x)