minor: Add expr_bin constructor to SyntaxFactory

This commit is contained in:
Giga Bowser 2024-11-21 15:16:06 -05:00
parent 6406048626
commit fbb392062a

View file

@ -80,6 +80,23 @@ impl SyntaxFactory {
ast
}
pub fn expr_bin(&self, lhs: ast::Expr, op: ast::BinaryOp, rhs: ast::Expr) -> ast::BinExpr {
let ast::Expr::BinExpr(ast) =
make::expr_bin_op(lhs.clone(), op, rhs.clone()).clone_for_update()
else {
unreachable!()
};
if let Some(mut mapping) = self.mappings() {
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
builder.map_node(lhs.syntax().clone(), ast.lhs().unwrap().syntax().clone());
builder.map_node(rhs.syntax().clone(), ast.rhs().unwrap().syntax().clone());
builder.finish(&mut mapping);
}
ast
}
pub fn expr_path(&self, path: ast::Path) -> ast::Expr {
let ast::Expr::PathExpr(ast) = make::expr_path(path.clone()).clone_for_update() else {
unreachable!()