Meaningful identifiers and other multi-token keywords

Tim tim.dlang at t-online.de
Wed Sep 25 15:50:20 UTC 2024


On Tuesday, 24 September 2024 at 20:37:36 UTC, Quirin Schroll 
wrote:
> I want to suggest moving the parsing of scope guards and 
> linkages to the lexer, i.e., if the lexer sees `scope`, `(`, 
> any one of the identifiers `exit`, `success`, or `failure`, and 
> `)`, that is a scope guard and is treated as a single token.
>
> The same with `extern(C)` – it will never be seen as anything 
> but a linkage. It’s a multi-token keyword.

I don't think, the lexer would be the right place, because the 
constructs are still multiple tokens. For example whitespace and 
comments are allowed in `extern  (  C  ++ /*comment*/ )`.

Unknown languages in `extern(...)` attributes should also produce 
errors, so future compilers can add them without breaking code. 
Consider this example:
```
extern(X) x = 0;
````
Currently `X` is a normal identifier, but in the future it be 
could another language supported by the compiler. If `(X)` is 
interpreted as a type, then adding `extern(X)` to the compiler 
would be a breaking change. For forward compatibility it would be 
best if `extern(...)` and `scope(...)` are always parsed as whole 
attributes and not attributes with types in parens. Unknown 
languages or scope guard identifiers would then produce errors, 
so future compilers could add them without breaking code.



More information about the Digitalmars-d mailing list