accept @pure @nothrow @return attributes

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 26 12:34:33 PST 2015


On Monday, 26 January 2015 at 19:44:18 UTC, Walter Bright wrote:
> On 1/26/2015 8:13 AM, Foo wrote:
>> You could do the same as C++ with override and final: they are 
>> only valid
>> attributes if they appear _after_ the function/method. 
>> Elsewhere they are still
>> valid as identifiers for e.g. variables.
>
> Just 'no' on context-sensitive tokens.
>
> For context,
>
>   TV vocabulary - 2,000 words
>   High school vocabulary - 10,000 words
>   College vocabulary - 30,000 words
>   English - 1,000,000 words
>
> i.e. words are NOT a scarce resource (quite unlike punctuation).

I'm not sure what you mean by "context-sensitive tokens".  It 
sounds like you might be saying that this requires the tokenizer 
to be context sensitive, but this isn't the case.  Instead, 
allowing a function to be decorated with any number of "id"  or 
"keyword" tokens would allow the language to add new attributes 
(without a '@' character) by restricting the usage of attributes 
in the semantics instead of the syntax.

void myfunc() foo bar safe nogc nothrow {
}

'foo' and 'bar' don't break the syntax but are caught by the 
semantic analysis.

Furthermore, I'm sure this type of thing is already done all over 
the place in the grammar.  The following example comes to mind:

struct St { }
void main()
{
   St St;
}

The "St" token is a decl type the first time and a variable name 
the second.  I'm sure they are implemented as the same token but 
the grammar results in a different semantic meaning for both 
tokens.


More information about the Digitalmars-d mailing list