mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
remove fragments from syntax
This commit is contained in:
parent
dacbc6a69a
commit
55f1564101
20 changed files with 0 additions and 98 deletions
|
@ -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<Self, ()> {
|
|
||||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Pattern)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ast::Expr {
|
impl ast::Expr {
|
||||||
/// Returns `text`, parsed as an expression, but only if it has no errors.
|
/// Returns `text`, parsed as an expression, but only if it has no errors.
|
||||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn parser_fuzz_tests() {
|
fn parser_fuzz_tests() {
|
||||||
for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) {
|
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());
|
assert!(!errors.is_empty(), "There should be errors in the file {:?}", path.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fragment_parser_dir_test<T, F>(ok_paths: &[&str], err_paths: &[&str], f: F)
|
|
||||||
where
|
|
||||||
T: crate::AstNode,
|
|
||||||
F: Fn(&str) -> Result<T, ()>,
|
|
||||||
{
|
|
||||||
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`
|
/// Calls callback `f` with input code and file paths for each `.rs` file in `test_data_dir`
|
||||||
/// subdirectories defined by `paths`.
|
/// subdirectories defined by `paths`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
ERROR
|
|
|
@ -1 +0,0 @@
|
||||||
fn fn foo() {}
|
|
|
@ -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 "}"
|
|
|
@ -1 +0,0 @@
|
||||||
fn foo() {}
|
|
|
@ -1 +0,0 @@
|
||||||
ERROR
|
|
|
@ -1 +0,0 @@
|
||||||
struct
|
|
|
@ -1 +0,0 @@
|
||||||
ERROR
|
|
|
@ -1 +0,0 @@
|
||||||
a + b
|
|
|
@ -1,4 +0,0 @@
|
||||||
PATH@0..3
|
|
||||||
PATH_SEGMENT@0..3
|
|
||||||
NAME_REF@0..3
|
|
||||||
IDENT@0..3 "foo"
|
|
|
@ -1 +0,0 @@
|
||||||
foo
|
|
|
@ -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"
|
|
|
@ -1 +0,0 @@
|
||||||
foo::bar::baz
|
|
|
@ -1 +0,0 @@
|
||||||
ERROR
|
|
|
@ -1 +0,0 @@
|
||||||
ERROR
|
|
|
@ -1 +0,0 @@
|
||||||
Some(x
|
|
|
@ -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 ")"
|
|
|
@ -1 +0,0 @@
|
||||||
Some(x)
|
|
Loading…
Reference in a new issue