labath wrote:
> > As for the syntax for alternatives, I was suggesting (privately, I think)
> > to use :-, as that what
> > [bash](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html)
> > uses for conditional expansion (and the formatter language feels more like
> > bash than C). However, I am having some doubts about that now since the way
> > you're thinking of using it is not exactly bash-like (the :- thingy only
> > works for a single variable, but I think you want to mostly use it on the
> > block level (and bash doesn't have blocks))
>
> Would the syntax be `${some.variable :- fallback.variable}`? Which would try
> the first and if that fails try the fallback? This would work for my
> use-case. I.e., `${function.formatted-arguments :- function.arguments}`
So, the bash syntax requires another level of `${}` if you want to treat the
RHS as a variable (I guess, because something like `echo "FOO is
${FOO:-unset}"` is a common pattern). It also requires there be no spaces
around the `:-` thingy.
```
$ FOO=bar
$ echo ${NOTSET:-FOO}
FOO
$ echo ${NOTSET:-${FOO}}
bar
$ echo ${NOTSET :- ${FOO}}
bash: ${NOTSET :- ${FOO}}: bad substitution
```
If it were to be used only on a single variable, then I think this syntax is
great (including the nested expansion, since you also might want to replace the
expansion with a constant string). For blocks (which I think makes sense), I'm
less sure.
There's also a question of how to parse that (i.e., how to print a literal
`:-`). With a single variable that's not an issue since variable names can't
contain `:`). Though that's kind of a question regardless of the string...
https://github.com/llvm/llvm-project/pull/137408
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits