syntax,ssr: Implement statement parsing

This commit is contained in:
Marijn Suijten 2020-11-17 15:34:41 +01:00
parent 354c1daedc
commit cc081b7e1c
31 changed files with 167 additions and 0 deletions

View file

@ -212,6 +212,13 @@ impl ast::Attr {
}
}
impl ast::Stmt {
/// Returns `text`, parsed as statement, but only if it has no errors.
pub fn parse(text: &str) -> Result<Self, ()> {
parsing::parse_text_fragment(text, parser::FragmentKind::Statement)
}
}
/// Matches a `SyntaxNode` against an `ast` type.
///
/// # Example:

View file

@ -102,6 +102,15 @@ fn type_parser_tests() {
);
}
#[test]
fn stmt_parser_tests() {
fragment_parser_dir_test(
&["parser/fragments/stmt/ok"],
&["parser/fragments/stmt/err"],
crate::ast::Stmt::parse,
);
}
#[test]
fn parser_fuzz_tests() {
for (_, text) in collect_rust_files(&test_data_dir(), &["parser/fuzz-failures"]) {