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.
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.
Please sign in to leave a comment.
Vaclav
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
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.
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