New syntax for comma expression
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Nov 21 02:09:14 UTC 2024
On 21/11/2024 2:59 PM, Paul Backus wrote:
> On Wednesday, 20 November 2024 at 23:11:37 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> During semantic analysis, some code gets lowered to the comma expression.
>>
>> [...]
>>
>> Proposed grammar:
>>
>> ```diff
>> CommaExpression:
>> + "class" ConstructorArgs|opt AnonBaseClassList|opt AggregateBody
>> + "__commaExpr" '(' CommaExpression ')'
>> ```
>
> As a general rule, I don't think we should be adding new syntax to D
> because it's easier for the compiler to generate than the existing syntax.
This is not an ease of use situation.
There is nothing for the lowering to map to in the syntax.
I.e.
```d
void main() {
bool b;
auto v = b ? (
new class LeClass, LeInterface {}
) : (
new class LeClass, LeInterface {}
);
}
```
```
void main()
{
bool b = false;
LeClass v = b ? LeClass, LeInterface
{
void* this;
@system this()
{
super.this();
return this;
}
}
, new __anonclass2 : (LeClass, LeInterface
{
void* this;
@system this()
{
super.this();
return this;
}
}
, new __anonclass3);
return 0;
}
```
Can't go and mess around with statement insertion for something like
this. Of course feel free to try ;)
> If there's something in D's semantics that the existing syntax *can't
> express*, then there's a discussion to be had. But I don't think this
> qualifies.
Yup, there is plenty unfortunately.
https://github.com/search?q=repo%3Adlang%2Fdmd+%22new+CommaExp%22&type=code
More information about the dip.ideas
mailing list