In D, lexically, which are the chars that can follow $, exactly ?

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 13 08:37:15 PDT 2016


On Sunday, 13 March 2016 at 14:55:36 UTC, Marc Schütz wrote:
> On Sunday, 13 March 2016 at 14:07:31 UTC, Basile B. wrote:
>> '$' is only valid in an indexExpression 
>> (https://dlang.org/spec/grammar.html#IndexExpression),
>> so it can only be followed by
>>
>> - ' '
>> - ']'
>> -  operators , usually '-' but also '/', '+', '>>' etc
>>
>> Is that right ?
>>
>> I'd like to relax the lexical rule for C.E static macros which 
>> currently is
>>
>> - "^\$\w*[a-zA-Z]$", so for example "$a1A" is valid and "$a1" 
>> is not.
>>
>> But it looks like for example "$)" or "$}" wouldn't be 
>> ambiguous since it's not possible in D.
>
> I don't know what C.E is, but `$` is an expansion of 
> `PrimaryExpression`, which means it can (syntactically) appear 
> anywhere a `PrimaryExpression` is allowed. For example, this 
> compiles:
>
>     void main() {
>         int[] a;
>         a[0 .. ($)] = 0;
>     }

Then the C.E macros syntax can't be enhanced. At least the 
current is not ambiguous.

The thing is that a macro is substitued automatically/dynamically 
so the requirement is that nothing that's syntaxically valid in D 
must replacable.


More information about the Digitalmars-d-learn mailing list