elena-lang icon indicating copy to clipboard operation
elena-lang copied to clipboard

Support enumeration list

Open arakov opened this issue 8 years ago • 1 comments

Enumeration list (set of named constants) should be supported.

The proposed syntax:

enum Color : enumeration(Red = 1, Blue = 2, Green = 3);

public program()
{
    Color color := Color.Red; 
}

arakov avatar Aug 05 '16 07:08 arakov

A special template might be introduced - enumof So for example the following C code

enum { RED, GREEN, /*...*/ WHITE } 

will look in ELENA:

#subject color = enumof:int.

#symbol(color)RED   = 0FF0000h.
#symbol(color)GREEN = 000FF00h.
// ...
#symbol(color)WHITE = 0FFFFFFh.

arakov avatar Aug 08 '16 13:08 arakov

Special attribute is introduced enumlist.

The base class is stateless and limited and cannot be directly initiated, though it is possible to return the children. All children / enum list values should be declared in the same module.

#class(enumlist)Color
{
     #constructor red = RED.

     #constructor greeen = GREEN.

     #method int = $nil.
}

#symbol RED = Color
{
    #method int = 0FF0000h.
}

#symbol GREEN= Color
{
    #method int = 000FF00h.
}

arakov avatar Sep 26 '16 09:09 arakov