Open FroMage opened 3 years ago
/cc @mkouba
Yes, {bool ? expr1 : expr2}
works but you cannot use nested operators ATM.
The value expressions are currently designed a little bit differently, i.e. not as a full featured statements or expressions. That said, it should be fairly easy to implement simple operators (such as foo > 1 ? 'big' : 'small'
) but not complex expression. We could definitely try to revisit our design and API.
Yeah, it would be nice to make value expressions full-fledged expressions, that's much more intuitive and useful.
FTR, the operators are actually implemented as "virtual methods" that can be used with infix notation in output expressions, so bool ? expr1 : expr2
can be translated to bool.ifTruthy(expr1).or(expr2)
and this form works everywhere.
Sure, but that's a workaround.
For the record - https://github.com/quarkusio/quarkus/pull/29154 makes it possible to use the infix notation in section params with parentheses, e.g. you can do something like {#let foo = (val ? 1 : 2)}
.
ATM it appears that boolean expressions and comparison operators are only available in
#if
tags. I tried using them in the{bool ? expr1 : expr2}
ternary and they didn't appear to work.If it's at all possible with the internals, we should make sure that every expression passed to a any tag is evaluated with the same grammar, like in programming languages we have statements and expressions, and every expression can occur in every context.
The way this is usually done is by having an
evaluate/parseExpression(Expression)
which then switches/delegates to the next operator precedence, sayevaluate/parseParenthesis(ParenExpression)
orevaluate/parseComparison(ComparisonExpression)
until we get to the bottom of the expression.And then every tag would use the same expresion evaluation, with different scopes naturally.