mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
expr: short-circuit evaluation for |
This commit is contained in:
parent
fa2a14ccd2
commit
2c2e01205c
1 changed files with 17 additions and 1 deletions
|
@ -155,8 +155,24 @@ impl AstNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn operand_values(&self) -> Result<Vec<String>, String> {
|
pub fn operand_values(&self) -> Result<Vec<String>, String> {
|
||||||
if let Self::Node { operands, .. } = self {
|
if let Self::Node {
|
||||||
|
operands, op_type, ..
|
||||||
|
} = self
|
||||||
|
{
|
||||||
let mut out = Vec::with_capacity(operands.len());
|
let mut out = Vec::with_capacity(operands.len());
|
||||||
|
let mut operands = operands.iter();
|
||||||
|
|
||||||
|
if op_type == "|" {
|
||||||
|
if let Some(value) = operands.next() {
|
||||||
|
let value = value.evaluate()?;
|
||||||
|
out.push(value.clone());
|
||||||
|
if value_as_bool(&value) {
|
||||||
|
out.push(String::from("dummy"));
|
||||||
|
return Ok(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for operand in operands {
|
for operand in operands {
|
||||||
let value = operand.evaluate()?;
|
let value = operand.evaluate()?;
|
||||||
out.push(value);
|
out.push(value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue