implement |> and <|

This commit is contained in:
2026-05-02 17:05:49 +08:00
parent 4419d38eb9
commit 2c4c325307
3 changed files with 28 additions and 43 deletions
+28 -1
View File
@@ -266,10 +266,37 @@ impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>> Downgrade<'id, 'ir, Ctx> fo
impl<'id: 'ir, 'ir, Ctx: DowngradeContext<'id, 'ir>> Downgrade<'id, 'ir, Ctx> for ast::BinOp {
fn downgrade(self, ctx: &mut Ctx) -> Result<GhostRoIrRef<'id, 'ir>> {
use ast::BinOpKind as Kind;
use BinOpKind::*;
let span = self.syntax().text_range();
let lhs = self.lhs().require(ctx, span)?.downgrade(ctx)?;
let rhs = self.rhs().require(ctx, span)?.downgrade(ctx)?;
let kind = self.operator().require(ctx, span)?.into();
let kind = match self.operator().require(ctx, span)? {
Kind::Concat => Con,
Kind::Update => Upd,
Kind::Add => Add,
Kind::Sub => Sub,
Kind::Mul => Mul,
Kind::Div => Div,
Kind::And => And,
Kind::Equal => Eq,
Kind::Implication => Impl,
Kind::Less => Lt,
Kind::LessOrEq => Leq,
Kind::More => Gt,
Kind::MoreOrEq => Geq,
Kind::NotEqual => Neq,
Kind::Or => Or,
Kind::PipeLeft => {
let arg = ctx.maybe_thunk(rhs);
return Ok(ctx.new_expr(Ir::Call { func: lhs, arg, span }))
},
Kind::PipeRight => {
let arg = ctx.maybe_thunk(lhs);
return Ok(ctx.new_expr(Ir::Call { func: rhs, arg, span }))
},
};
Ok(ctx.new_expr(Ir::BinOp { lhs, rhs, kind }))
}
}
-30
View File
@@ -265,36 +265,6 @@ pub enum BinOpKind {
// Set/String/Path operations
Con, // List concatenation (`++`)
Upd, // AttrSet update (`//`)
// Not standard, but part of rnix AST
PipeL,
PipeR,
}
impl From<ast::BinOpKind> for BinOpKind {
fn from(op: ast::BinOpKind) -> Self {
use BinOpKind::*;
use ast::BinOpKind as kind;
match op {
kind::Concat => Con,
kind::Update => Upd,
kind::Add => Add,
kind::Sub => Sub,
kind::Mul => Mul,
kind::Div => Div,
kind::And => And,
kind::Equal => Eq,
kind::Implication => Impl,
kind::Less => Lt,
kind::LessOrEq => Leq,
kind::More => Gt,
kind::MoreOrEq => Geq,
kind::NotEqual => Neq,
kind::Or => Or,
kind::PipeLeft => PipeL,
kind::PipeRight => PipeR,
}
}
}
/// The kinds of unary operations.