Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to transform my dsl to more target languages?
How to transform my dsl to more target languages? [message #1440633] Wed, 08 October 2014 16:26 Go to next message
Marko Markovic is currently offline Marko MarkovicFriend
Messages: 35
Registered: August 2014
Member
I would like to transform my dsl to more target languages (java, javascript, python..), something like this:

def dispatch void infer or doGenerate(...){
switch(temp){
javascript:{
//transform to javascript, mydsl.js
}
python:{
//transform to python, mydsl.py
}
java:{
//transform to java, mydsl.java
}
}
}

Does anyone have any ideas?

Thank you in advance,
Marko
Re: How to transform my dsl to more target languages? [message #1440656 is a reply to message #1440633] Wed, 08 October 2014 17:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi you can call FSA.generateFile AS often as you want. For a starting point have a look at the xtext tutorial

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to transform my dsl to more target languages? [message #1441117 is a reply to message #1440656] Thu, 09 October 2014 09:28 Go to previous messageGo to next message
Marko Markovic is currently offline Marko MarkovicFriend
Messages: 35
Registered: August 2014
Member
Thank you Christian,

I use xbase and I have MyDslJvmModelInferrer, how can I use and infer and doGenerate(fsa.generateFile) in same time?

I tried to write class MyDslGenerator.xtend with doGenerate method and bind it in MyDslRuntimeModule
public Class<? extends IGenerator> bindIGenerator() {
return MyDslGenerator.class;
}

After that, it generated code which is specified by doGenerate method but it didn't generate code specified by infer method.

Best regards,

Marko
Re: How to transform my dsl to more target languages? [message #1441129 is a reply to message #1441117] Thu, 09 October 2014 09:43 Go to previous messageGo to next message
Tobias Wink is currently offline Tobias WinkFriend
Messages: 20
Registered: September 2014
Junior Member
I'm using both the ModelInferrer and the ModelGenerator. To enable this I followed an article on rcpVision (www.rcp-vision.com/?p=1640). I removed the http, because I'm not allowed to post links other than to eclipse.org urls
Re: How to transform my dsl to more target languages? [message #1441156 is a reply to message #1441129] Thu, 09 October 2014 10:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

you can subclass JvmModelGenerator


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to transform my dsl to more target languages? [message #1441541 is a reply to message #1441156] Thu, 09 October 2014 22:07 Go to previous messageGo to next message
Marko Markovic is currently offline Marko MarkovicFriend
Messages: 35
Registered: August 2014
Member
Thank you Tobias and Christian,
Tobias I followed that article but I have problem. Next code snippet

def compile(XExpression xExpression, ImportManager importManager) {
val result = new StringBuilderBasedAppendable(importManager)
xbaseCompiler.toJavaStatement(xExpression, result, true)
result
}
has error "Type mismatch: cannot convert from StringBuilderBasedAppendable to ITreeAppendable"

Christian, I think I didn't understand your reply.

Thank you on your reply in advance,

Marko



Re: How to transform my dsl to more target languages? [message #1441709 is a reply to message #1441541] Fri, 10 October 2014 04:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

the model that is created by the jvmmodelinferrer is translated into java source code by the jvmmodelgenerator.
so if you want to hook into that process you can subclass jvmmodelgenerator, hook into doGenerate and bind it as IGenerator.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to transform my dsl to more target languages? [message #1444846 is a reply to message #1441129] Tue, 14 October 2014 16:28 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 09/10/2014 11:43, Tobias Wink wrote:
> I'm using both the ModelInferrer and the ModelGenerator. To enable this
> I followed an article on rcpVision (www.rcp-vision.com/?p=1640). I
> removed the http, because I'm not allowed to post links other than to
> eclipse.org urls

Hi

I wrote that article, but that's rather old now, especially now that
Xbase evolved in such a way that the approach described in that article
does not work anymore :)

you should really implement the model inferrer so that the Xbase
typesystem works, and let the JvmModelGenerator do all the rest.

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Access AST generated in Xtexteditor
Next Topic:Concept to avoid lengthy generator steps?
Goto Forum:
  


Current Time: Thu Sep 19 05:05:57 GMT 2024

Powered by FUDForum. Page generated in 0.04756 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top