feat: array match

This commit is contained in:
bvanjoi 2023-01-18 20:23:12 +08:00
parent 3a72713365
commit 8fa69f9f7d
3 changed files with 157 additions and 11 deletions

View file

@ -520,6 +520,15 @@ pub fn literal_pat(lit: &str) -> ast::LiteralPat {
}
}
pub fn slice_pat(pats: impl IntoIterator<Item = ast::Pat>) -> ast::SlicePat {
let pats_str = pats.into_iter().join(", ");
return from_text(&format!("[{pats_str}]"));
fn from_text(text: &str) -> ast::SlicePat {
ast_from_text(&format!("fn f() {{ match () {{{text} => ()}} }}"))
}
}
/// Creates a tuple of patterns from an iterator of patterns.
///
/// Invariant: `pats` must be length > 0