Standard Library · expr
class Bin
A binary operation: l op r.
since 0.1.0-alpha.1linuxwindowswasm
- bases
Node
Overview
op is one of ==, !=, <, <=, >, >=, &&, ||, +, -, *, / or %. The operands keep the order they were written in.
Examples
expr::Node tree = expr::Bin("&&", expr::Field(["active"]), expr::Bin(">=", expr::Field(["age"]), expr::Lit(18)));
match (tree) {
expr::Bin => {
expr::Bin b = tree;
console.writeln("${b.op} of two operands");
match (b.r) {
expr::Bin => { expr::Bin r = b.r; console.writeln("right side: ${r.op}"); }
else => { console.writeln("right side: other"); }
}
}
else => { console.writeln("not a Bin"); }
}
&& of two operands
right side: >=
Constructors
new
Create a binary-operation node.
Parameters
- o
- The operator text.
- left
- The left operand.
- right
- The right operand.
Examples
expr::Bin b = expr::Bin(">=", expr::Field(["age"]), expr::Lit(18));
console.writeln(b.op);
match (b.l) {
expr::Field => { console.writeln("left is a field"); }
else => { console.writeln("left is something else"); }
}
>=
left is a field
Fields
l
Node lThe left operand.
op
string opThe operator text, for example ">=" or "&&".
r
Node rThe right operand.
See also
- Un — A unary operation:
!eor-e.