Don't know how to proceed with Generator

Hi,

I am new to MPS and am trying to create a Restaurant Workflow DSL. My goal is to transform this into MPS Baselang and have Java generated.

I have created the concepts and their respective editors . My language now looks like this:

Each Workflow(concept) consists of many WorkflowStep(concept) elements. Each WorkflowStep consists of a Person(Customer, Chef, Waiter etc. which are all concepts) and each Person can do some action(concept) eg: place an order, cook meal, deliver meal etc.
What I want to end up with is a Workflow class that has instance variables of type Customer, Chef etc.

AND an execute method which calls relevant methods for each person,i.e, something that looks as follows:

public void execute() {

     customer.placeOrder();

     chef.cookMeal();

     .....

}

So it involves creation of multiple classes: 1 for each person with respective methods.

Also, it involves some string manipulation: eg: the action defined as places an order in the DSL needs to be transformed to something that looks like placeOrder().

I looked at the Generator tutorials multiple times on youtube but I am not sure how to proceed. I think my solution has some things in common with the SampleHeatingController solution shipped with MPS but I could not find any generator stuff there.

Can somebody help me out please? Many thanks!

4 comments
Comment actions Permalink

Just write some classes in the generator that look like an example of the resulting code, then start annotating the bits that should be calculated (as opposed to the static boilerplate) with generator annotations, where you tell the generator how to compute the necessary values.

0
Comment actions Permalink

Hi,

Thanks for your reply. I am able to transform my Workflow concept into a class. However, I am unable to transform my Person concept into a class (since it is not a root concept). 

Can I generate classes only from root concepts?
My end goal is to have a workflow class with all the persons declared as field variables within it. It should look like this...
public class $[WorkflowName] {

        public Person $[PersonName1];

        public Person $[PersonName2];

}

Can you help me out please.

0
Comment actions Permalink

When you create a root in the generator model, it will automatically get annotated with a "root template" annotation. You can specify the input concept there and add generator macros. Then you also need to register the template in the mapping configuration as a "root mapping rule".

1
Comment actions Permalink

Hello SIr,

Thank you for your response. I have made some progress and some new questions have popped up.

I thought it would be better to write a new post with full context.

It is here: https://mps-support.jetbrains.com/hc/en-us/community/posts/115000710264-Unresolved-references-in-Generated-text

Thank you!

1

Please sign in to leave a comment.