[SOLVED] Access concepts as Java-instance-reference from inline BlockStatement


I am currently trying to create a language that helps to create (otherwise repetitive) Informer/Listener setups. We have a custom middleware which I import in a runtime solution (see first screenshot).

The (yet simple) language itself allows to create a class sheet (-> generated into a Java classe) that can hold informers and listeners (-> generated into instantiated class variables of the type Listener and Informer provided by the runtime jar import).

Further there is an annotation that allows to define a function that is also added to the class.

The generation and all required referencing works perfectly fine.

However, I would like to allow the user to use participants (e.g. myInformer and myListener) within the inline code block (e.g. like the 'hw' above) and reference to them or use dot operations (e.g. an informer provides the method activate()):

I struggle with this as this is before generation, so there is no actual type of an informer/listener attached to the concepts. I think it can be solved by adding the correct type information to the informer and listener concept?

But then I also am not sure how (and where) I will have to influence the scoping so that 'myInformer' will appear in the BlockStatement?


I am aware that the mbeddr project similarly allows inline c code but unfortunately I could not identify how they do it. 

Can someone point me in the correct direction on how to realize this?

Thanks in advance for any help!


Comment actions Permalink

You will need to extend baselanguage with concepts that will represent things like "myInformer" in blocks of base language code. These concepts should most likely extend "Expression" and contain a reference of cardinality 1 pointing to an Informer/Listener.

For the operations invokable through DotExpression on the informers, you could get some inspiration from the "languagePatterns" sample project (bundled with MPS), which defines a few sample operations underneath "dotexpression".



Comment actions Permalink

Thanks for the quick response! Indeed this allows to create the reference and according operations - and its so obvious now :) Thank you!

However this means that I will have to re-implement all functions as concepts (i.e. operations), correct? I was hoping that there is an easier way by e.g. by holding a dummy informer internally and 'forwarding' the possible operations?

Comment actions Permalink

You can create an IOperation that refers to the desired "function", e.g.:

concept MethodOperation extends IOperation 
implements <none>

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

<< ... >>

<< ... >>

target : ListenerFunction[1]

Additionally you'll have to define scoping rules in the Constraints of this concept. This way you'll get operations for all functions defined on the target Listener.

Comment actions Permalink

Thanks for your hints. I managed to get everything to work as I wanted to. In case someone else ends up here, this is how i solved it:

My Listener concept now extends StaticFieldDeclaration. This requires the Listener to have a child called type. I fill this in the behaviour constructor via 

this.type = <Listener>;

The latter is actually a quotation of ClassifierType of the Informer class from the runtime jar import. Next I created a ListenerReference which extends another abstract class of mine (MyVariableReference) that extends VariableReference. Here the scoping is important: for the link to variableDeclaration I added something like

return new SimpleRoleScope(contextNode.ancestor<concept = Process>, link/Process : entities/, concept/Listener/) {
public string getName(node<> child) {
return child : INamedConcept.name;

Process is the "Sheet" containing my listeners. If I then add a BlockStatement to my listener I am able to use my reference and the ClassifierType allows me to access all the methods from the runtime!

The Generator is a bit tricky but nothing to fancy - using labels I could resolve everything just fine. Good luck ;)


Please sign in to leave a comment.