DIPX: Enum Literals / Implicit Selector Expression

Basile B. b2.temp at gmx.com
Sat Jun 25 20:48:15 UTC 2022


On Saturday, 25 June 2022 at 16:10:03 UTC, ryuukk_ wrote:
> I tried to implement this, i spent the whole day today on it, 
> unfortunately, i'm unable to make progress, [...]
> If anyone is willing to help me, that would be sweet

I've implemented something similar in styx, it's called "parent 
enum inference" but I dont know if it can be done the same way in 
DMD. The architecture of the compiler is only partially similar. 
I'll describe how this work for me, hope this'll help ;)

So in styx this works almost like a "WithStatement":

A. Scope

(Something that can be done very similarly in DMD)

When it is wished to inferer enum parent names, I push a scope. 
In this scope I add as member the equivalent of a "with" 
expression, That exp gives, as an IdentExp, the enum.

In my case I add really the same data type as with a 
WithStatement, but there's a flag used to distinguish expressions 
used for "with" and those used for "parent enum inference". This 
is because in styx there is no special syntax (in opposition to 
the leading dot proposed for what you try to implement), it is 
just specified that this is tried at the very end.

Finally when it is not required to infer anymore, pop the scope.

   related code:

   - 
https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/semantic/declarations.sx#L147
   - 
https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/scope.sx#L24

example use, when the switched expression is an enum and to allow 
inference on the cases:

   - 
https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/semantic/statements.sx#L681

B. Resolving

(That part would be very different in DMD)

When an identifier has been unsuccessfully resolved, the 
expressions added in the scope are tried.

- 
https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/semantic/expressions.sx#L2253




More information about the Digitalmars-d mailing list