mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12: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> {
|
||||
if let Self::Node { operands, .. } = self {
|
||||
if let Self::Node {
|
||||
operands, op_type, ..
|
||||
} = self
|
||||
{
|
||||
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 {
|
||||
let value = operand.evaluate()?;
|
||||
out.push(value);
|
||||
|
|
Loading…
Reference in a new issue