Custom expression

Hello,

I'm building a DSL in MPS for my bachelor thesis and need your help. I just started with MPS and got a lot of insight with the online documentation and also the two reference books on the jetbrains website. But I can't figure something out how to do it. To give you some insight, I want to build a language to support the JUnit framework in Java and generate testcode it in a simple manner.

It should look like this

<Class> Test
  • methods-
<method> with parameters <x> = <choose_input>, ... where result.size() >= 5
...

I'm now there were I select the java class, select the method according to this class and also the parameters, using typesystem, constrains. The tricky part where I'm stuck is the "where" part. What I want to do is to have the result of the method, or staticfields of the class and use it within a DotExpression or some other Expression.

My approach is that I have a "Field" concept where I use a reference to BaseMethodDeclaration and in the editor I can access the returnType. I also have a child Expression where I want to use my Type to use a comparison operator, or if it's a class a dot operator. I used constrains to have the right returnType of that particular method, but how can I manipulate this that in the editor stands: 'result' and I can make Expression on that? I'm just clueless, I couldn't find anything in the examples or anywhere online. Maybe you can give me some hint how to go about this. I appreciate any help you can give me.

Michael
4 comments
Hi Michael,

if I understand the problem correctly, you need to define a "MethodResult" concept, such as:

concept MethodResult extends Expression    
      implements <none>     
             
  instance can be root: false 
  alias: result
  ...
prettyPrint();

with an editor holding a single constant "result" cell and a type-system rule:
rule typeof_MethodResult {         
  applicable for concept = MethodResult as methodResult          
  overrides false   
     
  do {              
    typeof(methodResult) :==: methodResult.ancestor<concept = TestStatement>.method.returnType;
  }  
}    
prettyPrint();

This will give you the type checks needed as well as the desired DotExpression behaviour.

Vaclav
0
Thanks for your input, but it doesn't work quite yet. It looks now like this:

MethodResult
concept MethodResult extends Expression     
      implements <none>      
              
instance can be root: false 
alias: <no alias> 
short description: <no short description> 
 
properties: 
<< ... >> 
 
children: 
<< ... >> 
 
references: 
result : MethodRef[1]
prettyPrint();

typeof_MethodResult
rule typeof_MethodResult {   
  applicable for concept = MethodResult as methodResult    
  overrides false            
              
  do {        
    typeof(methodResult) :==: methodResult.result.targetMethod.returnType;
  }           
}
prettyPrint();

MethodResult_Editor
<default> editor for concept MethodResult    
  node cell layout:           
     ( % result % -> ( % targetMethod % -> ( % returnType % -> result ) ) )

  inspected cell layout:      
    <choose cell model>
prettyPrint();

But if I select the MethodResult and want to use an Expression on it this happens:
http://i.imgur.com/TAHV06o.png

I tried several things but couldn't solve it. Thanks in advance for your help!
0
I assume your methodResult child of your concept representing the "method with parameters ... where ..." line should be of concept Expression and not MethodResult. "<=" is an expression, MethodResult just its left child.
0

Please sign in to leave a comment.