Generators for different languages

I'm trying to build a DSL that I'll be able to eventually generate source code for different languages, specifically C#, Java, ObjC and JavaScript.
From what I understand BaseLanguage is a Java-like MPS language, so I think I'll need to create at least the subset I need to make C#-like, ObjC-like and JavaScript-like languages and then create TextGen for each of those languages.

1. Is that correct plan?
2. Assume it is how can I make my one DSL language generate different languages? For example, if I add more than one generator how to I control which one is used for code preview?

I have other questions but I want to get the base working and I'll ask more.

Thank you,
Ido.
4 comments
Hi Ido,

  1. This is a correct plan. With JavaScript you may benefit from http://mar9000.org/bliki/ecma-script-4-mps.html and perhaps help evolve this project further.
  2. This is a bit tricky at the moment. We plan to introduce better way to configure the build process in 3.4, but in 3.2 you'll have to follow certain pattern and manually change your model in order to trigger different generators.
    • For your DSL wrap each generator in a separate language, so the generators will not be part of the DSL definition
    • In each such generator-wrapping language define an empty root concept
    • In your model create a node of the root concept from the language, which holds the desired generator - this will mandate the use of the generator to generate your model.
    • Alternatively, you could modify the "Language engaged in generation" property of your models to tie a particular generator with your model

Vaclav
0
Hi,

1. Yes, this is (currently) the right way.
2. This is a good question! It was a huge pain point for me. However, the solution is quite simple. If you want to use multiple generators, just configure implement a mapping configuration for each target language and a script which i) Creates one copy of the input model per target language and ii) inserts a marker property which can be used in the generator mappings to control which one is responsible for the current copy (as far as I know you have to write the condition for all mapping rules since the mapping config is declarative). However, this is not the answer to your question, yet, but you'll need it when developing the generators. The code preview shows, as far as I know, the generated text for all generators you implemented. I did not find any property to decide which one is shown. However, you can change the order of the generation through the generator priorities.

I hope that helps!

Regards,
LaAck
0
Hi,
Thank you both for the answers.
I'm still new to MPS and only make my first steps but it helps know I'm on the right path.
I'm sure I'll post more questions as I progress.
One thing I'll be glad to know: will it be possible to generate the result source code from command line tool?

I'm asking this because we have build scripts and once this will be done I really want to automate this step too. I know it's a bit far but I just want to make sure this is possible.

Thank you,
Ido.
0
Hi Ido,

yes you can have your languages built from the command line - the MPS build language lets you describe your build process and generate build scripts, which you then run with Ant.

Vaclav
0

Please sign in to leave a comment.