I was surprised to find that as of v1.51, the following does not work:
arch := if os() == "macos" && arch() == "aarch64" { "arm64" } else { arch() }
print-arch:
echo {{ arch }}
According to the GRAMMAR.md, this is not valid syntax, but only because equality cannot exist outside of an if condition.
Last mention of conditional logic I found was here: #696 - has the situation changed?
To support this, the grammar would be updated to allow equality to appear as an expression outside an if condition, and if condition would become an arbitrary expression, or only disjunct if that's too much.
expression : disjunct || expression
| disjunct
- disjunct : conjunct && disjunct
- | conjunct
+ disjunct : condition && disjunct
+ | condition
+ condition : conjunct '==' conjunct
+ | conjunct '!=' conjunct
+ | conjunct '=~' conjunct
+ | conjunct
- conjunct : 'if' condition '{' expression '}' 'else' '{' expression '}'
+ conjunct : 'if' expression '{' expression '}' 'else' '{' expression '}'
| 'assert' '(' condition ',' expression ')'
| '/' expression
| value '/' expression
| value '+' expression
| value
- condition : expression '==' expression
- | expression '!=' expression
- | expression '=~' expression
&&/|| would have higher precedence, so a == b && c == d would parse as (a == b) && (c == d).
I'd be happy to take a stab at implementing this.
I was surprised to find that as of v1.51, the following does not work:
According to the
GRAMMAR.md, this is not valid syntax, but only because equality cannot exist outside of anifcondition.Last mention of conditional logic I found was here: #696 - has the situation changed?
To support this, the grammar would be updated to allow equality to appear as an expression outside an
ifcondition, andifcondition would become an arbitrary expression, or onlydisjunctif that's too much.expression : disjunct || expression | disjunct - disjunct : conjunct && disjunct - | conjunct + disjunct : condition && disjunct + | condition + condition : conjunct '==' conjunct + | conjunct '!=' conjunct + | conjunct '=~' conjunct + | conjunct - conjunct : 'if' condition '{' expression '}' 'else' '{' expression '}' + conjunct : 'if' expression '{' expression '}' 'else' '{' expression '}' | 'assert' '(' condition ',' expression ')' | '/' expression | value '/' expression | value '+' expression | value - condition : expression '==' expression - | expression '!=' expression - | expression '=~' expression&&/||would have higher precedence, soa == b && c == dwould parse as(a == b) && (c == d).I'd be happy to take a stab at implementing this.