Skip to main content



      Home
Home » Modeling » TMF (Xtext) » DSL2Model
DSL2Model [message #40596] Wed, 15 April 2009 14:26 Go to next message
Eclipse UserFriend
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 #40628 is a reply to message #40596] Wed, 15 April 2009 16:27 Go to previous messageGo to next message
Eclipse UserFriend
Hello Ioan,

your Xtext model file is actually the instance of the .ecore file you want
to have.

you can verify this e.g. by right click on the model -> then open with
-> then select e.g. Generic EMF Form Editor or other Dynamic EMF Editors.
Re: DSL2Model [message #40659 is a reply to message #40596] Wed, 15 April 2009 16:38 Go to previous messageGo to next message
Eclipse UserFriend
To be able to compare with emf compare you have to add your dsls
fileextensions to emf compare under window -> prefs -> general -> content
types
Re: DSL2Model [message #40687 is a reply to message #40628] Wed, 15 April 2009 22:22 Go to previous messageGo to next message
Eclipse UserFriend
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 #40718 is a reply to message #40687] Thu, 16 April 2009 02:34 Go to previous messageGo to next message
Eclipse UserFriend
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 #40747 is a reply to message #40596] Thu, 16 April 2009 05:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ioan,

here I provide a simple MWE workflow parsing your .DSL file, resulting
into .XMI file for further work with e.g. QVTo:

<workflow>
<property file="parse.properties"/>

<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
platformUri=".."/>

<component class="org.eclipse.xtext.MweReader">
<uri value="${modelFile}"/>
<outputSlot value="model"/>
<register
class="<your-MetaModel-StandAloneSetup-Class-generated-by-Xtext >"/>
</component>

<component class="org.eclipse.emf.mwe.utils.Writer">
<cloneSlotContents value="true"/>
<uri value="${targetFile}"/>
<modelSlot value="model" />
</component>

</workflow>

Don't forget to define modeFile and targetFile properies in
parse.properties file.

Regards,
Karel
Re: DSL2Model [message #40868 is a reply to message #40747] Thu, 16 April 2009 10:13 Go to previous messageGo to next message
Eclipse UserFriend
This is exactly what I was looking for, mainly the Writer/Reader classes
and what parameters I would need to use for DSL2Model(XMI) transformation.
I guess for .XMI to .DSL, I could use a different couple of Writer/Reader
classes.

Thanks Karel, that was really helpful!

Regards,

Ioan
Re: DSL2Model [message #40929 is a reply to message #40718] Thu, 16 April 2009 10:23 Go to previous messageGo to next message
Eclipse UserFriend
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 #41983 is a reply to message #40747] Tue, 28 April 2009 02:16 Go to previous messageGo to next message
Eclipse UserFriend
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 #42045 is a reply to message #41983] Tue, 28 April 2009 05:28 Go to previous messageGo to next message
Eclipse UserFriend
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 #42076 is a reply to message #42045] Tue, 28 April 2009 05:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #42169 is a reply to message #42076] Tue, 28 April 2009 11:02 Go to previous messageGo to next message
Eclipse UserFriend
I uploaded all my files at following location:

http://www.insighteck.com/dslarea

Directory Layout:

./grammars : contains the grammars for my DSLs
DSL Base Grammar: Datatype.xtext and GenerateDatatype.mwe
DSL Extended Grammar: DatatypeSpecification.xtext and
GenerateDatatypeSpecification.mwe

For runtime testing environment:

./runtime : contains relevant files I used to test the plugings
generated using Xtext

base.datatype (based on DSL Base Grammar)
datatype2model.mwe and datatype.properties - to transform *.datatype to
*.xmi

specs.dtspec (based on DSL Extended Grammar)
dtspec2model.mwe and dtspec.properties - to transform *.dtspec to *.xmi

Full archived projects (removed auto-generated source code)

./zips
DSL Base: com.insighteck.hl7.dsl.datatype.zip
DSL Extended: com.insighteck.hl7.dsl.dtspec.zip
Runtime Test Project: CutOne.zip

Thanks a lot for looking into my issue.

Regards,

Ioan
Re: DSL2Model [message #42204 is a reply to message #42169] Tue, 28 April 2009 12:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ioan,

please try to use a platform:/resource -URI in your properties-file
instead of a plain src/com/...-string.

The MWEReader can find and load the resource, but the URI of the
resource cannot be interpreted by the import uri resolver. Seems to be a
bug. Would you please be so kind and file a bugzilla?

Regards,
Sebastian


The fixed spec.properties:

projectName=CutOne
modelFile=platform:/resource/CutOne/src/com/insighteck/hl7/d sl/specs.dtspec
targetFile=model/DatatypeSpecification.xmi



Am 28.04.2009 17:02 Uhr, schrieb Ioan:
>
> I uploaded all my files at following location:
>
> http://www.insighteck.com/dslarea
>
> Directory Layout:
>
> ./grammars : contains the grammars for my DSLs DSL Base Grammar:
> Datatype.xtext and GenerateDatatype.mwe DSL Extended Grammar:
> DatatypeSpecification.xtext and GenerateDatatypeSpecification.mwe
> For runtime testing environment:
>
> ./runtime : contains relevant files I used to test the plugings
> generated using Xtext base.datatype (based on DSL Base Grammar)
> datatype2model.mwe and datatype.properties - to transform *.datatype to
> *.xmi
> specs.dtspec (based on DSL Extended Grammar)
> dtspec2model.mwe and dtspec.properties - to transform *.dtspec to *.xmi
>
> Full archived projects (removed auto-generated source code)
>
> ./zips DSL Base: com.insighteck.hl7.dsl.datatype.zip DSL Extended:
> com.insighteck.hl7.dsl.dtspec.zip
> Runtime Test Project: CutOne.zip
>
> Thanks a lot for looking into my issue.
>
> Regards,
>
> Ioan
>
Re: DSL2Model [message #42224 is a reply to message #42204] Tue, 28 April 2009 13:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

It works if I make the change suggested by you, however
DatatypeSpecification.xmi uses the cross-reference to
" platform:/resource/CutOne/src/com/insighteck/hl7/dsl/base.da tatype " and I
would like to use the "platform:/resource/model/Datatype.xmi". Is there
any way to substitute the default URI cross-reference?

I will file a bugzilla and I will post a link in a moment!

Thanks,

Ioan
Re: DSL2Model [message #42250 is a reply to message #42224] Tue, 28 April 2009 15:00 Go to previous messageGo to next message
Eclipse UserFriend
Ioan,

Note that platform:/resource/model/Datatype.xmi implies there is a
project called "model" in the workspace.

Keeping resource in the src folder seems problematic because the path to
it at development time is different than the path to it at runtime, when
using platform:/resource for addressing it. That's fine if all
references are to other resources also under "src" but if there are
references to things under a folder parallel to src, it's likely you'll
have problems at runtime because of relative path issues...


Ioan wrote:
> Hi Sebastian,
>
> It works if I make the change suggested by you, however
> DatatypeSpecification.xmi uses the cross-reference to
> " platform:/resource/CutOne/src/com/insighteck/hl7/dsl/base.da tatype "
> and I would like to use the "platform:/resource/model/Datatype.xmi".
> Is there any way to substitute the default URI cross-reference?
>
> I will file a bugzilla and I will post a link in a moment!
>
> Thanks,
>
> Ioan
>
Re: DSL2Model [message #42267 is a reply to message #42250] Tue, 28 April 2009 15:15 Go to previous messageGo to next message
Eclipse UserFriend
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 #42288 is a reply to message #42204] Wed, 29 April 2009 00:42 Go to previous messageGo to next message
Eclipse UserFriend
Here is the bugzilla link:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=274142

Regards, Ioan
Re: DSL2Model [message #42317 is a reply to message #42267] Wed, 29 April 2009 02:10 Go to previous messageGo to next message
Eclipse UserFriend
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 #42348 is a reply to message #42288] Wed, 29 April 2009 02:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, Iaon.

I'll have a look at it.

- Sebastian

Am 29.04.2009 6:42 Uhr, schrieb Ioan:
>
> Here is the bugzilla link:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=274142
>
> Regards, Ioan
>
Re: DSL2Model [message #42482 is a reply to message #42317] Wed, 29 April 2009 20:07 Go to previous message
Eclipse UserFriend
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
Previous Topic:[Xtext] Workflow invocation yields "Incompatible Classes" error
Next Topic:XText + XPand
Goto Forum:
  


Current Time: Thu Jul 17 18:55:35 EDT 2025

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

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

Back to the top