Grammar question. TypeSuffix - what is [ AssignExpression .. AssignExpression ] production for?

Paul Backus snarwin at gmail.com
Mon Sep 2 00:58:18 UTC 2024


On Monday, 2 September 2024 at 00:16:14 UTC, WB wrote:
> I am reading D grammar again
>
> and spotted on https://dlang.org/spec/grammar.html#TypeSuffix 
> and https://dlang.org/spec/type.html#grammar
>
> Something weird
>
> ```
> TypeSuffix:
>     *
>     [ ]
>     [ AssignExpression ]
>     [ AssignExpression .. AssignExpression ]
>     [ Type ]
>     delegate Parameters MemberFunctionAttributesopt
>     function Parameters FunctionAttributesopt
> ```
>
> 1st - pointers, 2nd - dynamic arrays, 3rd - static arrays, 5th 
> - associative arrays, 6/7 - delegate types.
>
>
> The 4th production would mean this is legal (syntactically) 
> variable definition:
>
> ```d
> string[5 .. 9] x;
> ```

```d
import std.meta: AliasSeq;

alias MyTypes = AliasSeq!(int, double, string);

MyTypes[1 .. 3] myVars;
static assert(is(typeof(myVars[0]) == double));
static assert(is(typeof(myVars[1]) == string));
```


More information about the Digitalmars-d mailing list