mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
internal: Add some pattern constructors to SyntaxFactory
This commit is contained in:
parent
ce2398fee8
commit
796041acce
1 changed files with 26 additions and 0 deletions
|
@ -127,6 +127,32 @@ impl SyntaxFactory {
|
|||
ast
|
||||
}
|
||||
|
||||
pub fn wildcard_pat(&self) -> ast::WildcardPat {
|
||||
make::wildcard_pat().clone_for_update()
|
||||
}
|
||||
|
||||
pub fn literal_pat(&self, text: &str) -> ast::LiteralPat {
|
||||
make::literal_pat(text).clone_for_update()
|
||||
}
|
||||
|
||||
pub fn tuple_struct_pat(
|
||||
&self,
|
||||
path: ast::Path,
|
||||
fields: impl IntoIterator<Item = ast::Pat>,
|
||||
) -> ast::TupleStructPat {
|
||||
let (fields, input) = iterator_input(fields);
|
||||
let ast = make::tuple_struct_pat(path.clone(), fields).clone_for_update();
|
||||
|
||||
if let Some(mut mapping) = self.mappings() {
|
||||
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
|
||||
builder.map_node(path.syntax().clone(), ast.path().unwrap().syntax().clone());
|
||||
builder.map_children(input.into_iter(), ast.fields().map(|it| it.syntax().clone()));
|
||||
builder.finish(&mut mapping);
|
||||
}
|
||||
|
||||
ast
|
||||
}
|
||||
|
||||
pub fn block_expr(
|
||||
&self,
|
||||
statements: impl IntoIterator<Item = ast::Stmt>,
|
||||
|
|
Loading…
Reference in a new issue