Enummember typing mystery

Let's create a new language under MPS. The language will be very simple and will contain:
1. concept named "Apple"
2. enumeration named "Color"

MPS source code goes below:


enumeration datatype Color

   member type       : string
   no default        : false
   default           : <1-st member>
   member identifier : derive from presentation

   value <NULL>   presentation red     (default)
   value <NULL>   presentation green            
   value <NULL>   presentation yellow  
         
concept Apple  extends    BaseConcept
              implements <none>

   instance can be root: false
   alias: <no alias>
   short description: <no short description>

   properties:
   color: Color

   children:
   << ... >>

   references:
   << ... >>

Now the funny part comes. I am adding "behavior" to the concept Apple:


concept behavior Apple {

    constructor {
       <no statements>
    }

    public enummember<Color> getTheColor() {
        return this.color;
    }


This method will not compile (!)

I browsed all the documentation, all examples and tutorials but was unable to understand what I am doing wrong. According to the "User's manual" the types are correct.

Please help :-)

I use build #MPS-135.1462

Regards
Wojtek
4 comments
The type of "this.color" is string, since an enum member is represented by the enum member's value in code. You need to get the enummember<> by using "enum/Color/.memberForValue(this.color)"

You may use the MPS 3.2 doc, which has made improvements in covering enums - https://confluence.jetbrains.com/display/MPSD32/Structure
0
Well .. that was really not obvious :-) Thanx Vaclav! By the way I am constantly running in a very basic problem - how to export sources done in my DSL in a text form. For example to attach above examples I had to manually rewrite them from MPS IDE (!) As of 2015 this sounds crazy... but is true..
0
Why not take screenshots and post them to the forum? It works well in my experience.
0
Indeed, the projectional editor has somewhat difficult life in the text-mostly world :)
Copy-paste from MPS should, however, work reasonably well for most cases, in my experience. E.g.:

concept Apple extends BaseConcept  
              implements INamedConcept            
     
  instance can be root: true 
alias: <no alias> 
short description: <no short description> 
 
properties: 
color : Color 
 
children: 
<< ... >> 
 
references: 
<< ... >>
prettyPrint();
0

Please sign in to leave a comment.