Home » Modeling » TMF (Xtext) » DSL2Model
DSL2Model [message #40596] |
Wed, 15 April 2009 14:26  |
Eclipse User |
|
|
|
I would like to use Xtext ( currently I have installed version 0.7.0
Release Date: 23/03/2009) to define a textual editor in order to capture
some informations from domain users. Following the sample described by
http://wiki.eclipse.org/Xtext/GettingStarted, I could easily create DLS
editor and run the Template.xpt using MWE workflow and generate the
output.txt based on DSL model I have created. But what I really want is to
transform my DSL model into a model that is a instance of the meta-model
generated by XText (.ecore meta-model) and use this model with other EMF
Tools ( Acceleo, M2M, EMF Compare etc) not only with Xpand to create a
textual output. Could someone tell me if Xtext can easily generate this
model instance or how can I extend Xtext to get a such model?
Thanks,
Ioan
|
|
| | | |
Re: DSL2Model [message #40718 is a reply to message #40687] |
Thu, 16 April 2009 02:34   |
Eclipse User |
|
|
|
Hi Ioan,
well, it's pure magic ;-)
Jokes aside: Xtext comes with an EMF Resource[1] implementation, that
allows any tool to use Xtext files. The parser etc. is selected
automagically. This decision is made due to the file extension, that you
use with your dsl. Ones you have successfully opened a resouce, any tool
can directly work with the model that has been loaded.
Please note, that arbitrary editors, that you use to open your dsl file,
do not know something about the special XtextResourceSet, that enables
classpath URIs. At the moment, you cannot use this advanced feature to
refer to other resources, if you want to use an editor that is not an
Xtext Editor with your dsl.
Hope that helps.
Regards,
Sebastian
[1]
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. emf.doc/references/javadoc/org/eclipse/emf/ecore/resource/pa ckage-summary.html
Am 16.04.2009 4:22 Uhr, schrieb Ioan:
> I thought it must be something very simple. If I would write a M2M QVTo
> transformation using as input meta-model the one generated by Xtext then
> if I want to run the transformation I could pass as input model
> parameter the Xtext model file? How would QVTo transformation know how
> to parse Xtext model file before applying transformation rules? The same
> applies when you have the meta-model generated by Xtext as output
> parameter for a QVTo transformation: can I tell QVTo to save the file
> directly to a Xtext model file or it does automatically if I have my
> Xtext plug-in installed?
>
> It would be much better to keep only one file (the Xtext model file) and
> use it with different transformers (QVTo/XPand/ATL/Acceleo).
>
> Thanks a lot Christian for your help, much appreciated :)
>
> Regards,
>
> Ioan
>
|
|
| | |
Re: DSL2Model [message #40929 is a reply to message #40718] |
Thu, 16 April 2009 10:23   |
Eclipse User |
|
|
|
Sebastian Zarnekow wrote:
> Hi Ioan,
> well, it's pure magic ;-)
> Jokes aside: Xtext comes with an EMF Resource[1] implementation, that
> allows any tool to use Xtext files. The parser etc. is selected
> automagically. This decision is made due to the file extension, that you
> use with your dsl. Ones you have successfully opened a resouce, any tool
> can directly work with the model that has been loaded.
> Please note, that arbitrary editors, that you use to open your dsl file,
> do not know something about the special XtextResourceSet, that enables
> classpath URIs. At the moment, you cannot use this advanced feature to
> refer to other resources, if you want to use an editor that is not an
> Xtext Editor with your dsl.
> Hope that helps.
> Regards,
> Sebastian
Hi Sebastian, you are right ... is magical:)
Based on what I understand, if I want to avoid translation of .DSL to
XMI as Karel suggested in a different post, somehow I have to tell my
QVTo transformation to use XtextResourceSet not XMIResourceSet.
Thanks Sebastian, Xtext is a really nice tool, I love it; also the
support here is fantastic, I get answers quite fast.
Regards,
Ioan
|
|
| | |
Re: DSL2Model [message #42076 is a reply to message #42045] |
Tue, 28 April 2009 05:45   |
Eclipse User |
|
|
|
Please post your Workflow-File, too.
- Sebastian
Am 28.04.2009 11:28 Uhr, schrieb Sven Efftinge:
> How do you refer to the other file?
> Could you post your models and the grammars?
>
> Sven
>
> Ioan schrieb:
>> Karel, based on your suggestion I was able to generate .xmi file from
>> a simple grammar. Now, I am trying to go one step further by creating
>> something more complex.
>> 1. Grammar baseGrammar - with no dependencies on other
>> grammars/meta-models other tan Terminals and import
>> "http://www.eclipse.org/emf/2002/Ecore" metamodel. 2. Grammar
>> specificationGrammar which depends on the baseGrammar and I used
>> import "uri_baseGrammar" as base. Also, I defined a cross-reference to
>> an type defined in baseGramar:
>>
>> TypeRef :
>> referenced = [base::Type];
>>
>> Following different tips from TMF Xtext Wiki and this Forum, I was
>> able to generate and create plugings for both DSLs and I could create
>> some sample DSL files: one instance for baseGrammar (base.datatype)
>> and one instance for specificationGrammar (specs.dtspec) which imports
>> first instance and uses a type defined in first instance as a
>> cross-reference. I have no errors so far.
>>
>> As per your suggestion, I could transform first instance based on
>> baseGrammar (base.datatype) to datatype.xmi but then when I tried for
>> the second instance which is based on specificationGrammar, I get the
>> .xmi file but the cross-references are lost and .mwe script displays
>> following error:
>>
>> [ERROR]: XtextLinkingDiagnostic: null:4 Cannot resolve reference to
>> 'Code'(Element: -UNKNOWN-; Reported by: MweReader: loading file from
>> src/../specs.dtspec)
>>
>> 'Code' is a Type I create in the first instance.
>>
>> What should I change for the second .mwe file (transforms specs.dtspec
>> to specs.xmi) to properly take the imported instance preserve the
>> cross-referenced elements? Right now, all values TypeRef.referenced
>> are empty but they are suppose to have a value TypeRef.referenced = code.
>>
>> Thanks in advance,
>>
>> Ioan
>>
|
|
| | | | | | |
Re: DSL2Model [message #42317 is a reply to message #42267] |
Wed, 29 April 2009 02:10   |
Eclipse User |
|
|
|
Hi Ioan,
please note, that Xtext comes with an implementation of an EMF Resource.
That way, there should not be much difference between your xmi-file and
the datatype-file from an EMF point of view. The framework will select a
resource factory based on the file extension and instantiate your model.
From my point of view, there is no need to serialize your data in xmi.
Regards,
Sebastian
Am 28.04.2009 21:15 Uhr, schrieb Ioan:
> Thanks Ed for suggestions, you are right I missed the project name:
> "platform:/resource/CutOne/model/Datatype.xmi"
>
> At this time I am not that worried about where I keep the models, I am
> just playing around to find out Xtext/EMF capabilities :) The main idea
> is that I want to have a href to generic "Datatype.xmi" instead of Xtext
> format ,"base.datatype". There is not much documentation, so I am
> changing things around trying to make it work :). One of the suggestion
> on forum was to use "classpath:/..." to define some references, that why
> I probably put the model into src directory.
>
> Thanks,
>
> Ioan
|
|
| |
Re: DSL2Model [message #42482 is a reply to message #42317] |
Wed, 29 April 2009 20:07  |
Eclipse User |
|
|
|
Sebastian Zarnekow wrote:
> Hi Ioan,
> please note, that Xtext comes with an implementation of an EMF Resource.
> That way, there should not be much difference between your xmi-file and
> the datatype-file from an EMF point of view. The framework will select a
> resource factory based on the file extension and instantiate your model.
> From my point of view, there is no need to serialize your data in xmi.
> Regards,
> Sebastian
Hi Sebastian,
I do understand that I could use Xtext Resource implementation but in
order to do that I would need to have the Xtext DSL Plugin installed. If I
use a central repository (I.E. EMF CDO) then I want only DSL user to have
the Xtext plugin installed and publish the generated metamodel (dsl.ecore)
and XMI models not the textual file .dsl, so other kind of developers
won't need to have Xtext DSL plugin installed.
Anyway, I found a solution, it might be a dirty hack but I does the job
:).
I extended Writer class adding one method:
class ConverterWriter extends Writer {
.....
public void addUriMap(final Mapping uriMap) {
log.info("Adding URI mapping from '" + uriMap.getFrom() + "' to '" +
uriMap.getTo() + "'");
final URI baseUri = URI.createURI(uriMap.getFrom());
final URI mappedUri = URI.createURI(uriMap.getTo());
if (mappedUri == null)
throw new ConfigurationException("cannot make URI out of " +
uriMap.getTo());
else {
URIConverter uriConvertor = new URIConverterImpl();
uriConvertor.getURIMap().put(baseUri,mappedUri);
getResourceSet().setURIConverter(uriConvertor);
}
}
}
And change specs2model.mwe to setup from/to:
<component class="com.pkg.ConverterWriter">
<cloneSlotContents value="true"/>
<uriMap>
<from value="platform:/resource/.../base.datatype"/>
<to value= "platform:/resource/.../model/Datatype.xmi"/>
</uriMap>
<uri value="${targetFile}"/>
<modelSlot value="model" />
</component>
</workflow>
Now I have the cross-reference the way I wanted.
Regards,
Ioan
|
|
|
Goto Forum:
Current Time: Thu Jul 17 18:55:35 EDT 2025
Powered by FUDForum. Page generated in 0.09010 seconds
|