Closed Sainan closed 2 months ago
How about a ? b <=> c : d
?
And I would also like
--- a/src/lparser.cpp
+++ b/src/lparser.cpp
@@ -3690,7 +3690,7 @@ static void expr (LexState *ls, expdesc *v, TypeHint *prop, int flags) {
luaK_patchtohere(fs, condition);
checknext(ls, ':');
ls->pushContext(PARCTX_TERNARY_C);
- expr(ls, v, prop);
+ expr(ls, v, prop, flags & E_NO_COLON);
ls->popContext(PARCTX_TERNARY_C);
luaK_exp2reg(fs, v, reg);
luaK_patchtohere(fs, escape);
for the ternary nested case. But this is my preference.
There is b ? c |> d : e : f()
which is parsed as b ? (c |> d : e) : f()
but this might make sense.
I'm personally not a huge fan of nested ternaries, but it's probably better to parse those with E_NO_COLON.
I am not even a fan of ternaries in lua due to the :
ambiguity (is it the end of the ternary or a method call?).
Well, we still have the if-expression type of ternary, but guess which one is more popular...
So, yeah, parsing it is really cursed, but people do prefer it.
To allow
a ? b in c : e
to be parsed as expected