Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Combining existing Model and own Grammar(EMF-Model + own Grammar = getting stuck? )
Combining existing Model and own Grammar [message #1003972] Tue, 22 January 2013 10:46 Go to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
Hello everyone,

i have a special problem concering XText, that seems not to be solveable with just asking google.

In the project i'm currently working in, we have a finished EMF Model, that we want to use in XText, so we imported it according to the XText Documentation.

import "link_to_model" as gruml
import "link_to_model/domains" as domains
import "link_to_model/structure" as structure (e.g.)

This already seems to work, now the problem occurs, we want to also use an own grammar that is not equivalent to the emf model. Model and Grammar belong together in a very complicated way, but the rules will not generate the imported model.
Now we started adding statements like:

SchemaName returns structure::Schema:
{name}
packagePrefix=PackageName name=QualifiedName ';'
;

to our grammar. As we are beginners in working with xtext,we now face a problem merging those two different parts into into project.
Is there a possibility to merge them in a right way? Is Xtext capable of using a grammar and an imported model, that don't fit together?

Don't ask why we need this, it is only important for us to get it working. We already read the documentation.

Would be pleased if someone could help us Smile

Greetings

Annika
Re: Combining existing Model and own Grammar [message #1004199 is a reply to message #1003972] Tue, 22 January 2013 19:27 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can have an external model (not generated from the grammar), and
have the generated parser instantiate that model.

There are certain rules however regarding containment/references,
scoping/linking etc. that affects how the language/support for the
language will behave.

If a good concrete syntax for the language requires a model that is to
far off from the existing model it may be better to perform
transformation in a build step.

Hope that helps.
- henrik

On 2013-22-01 14:35, Annika Wießgügel wrote:
> Hello everyone,
> i have a special problem concering XText, that seems not to be solveable
> with just asking google.
> In the project i'm currently working in, we have a finished EMF Model,
> that we want to use in XText, so we imported it according to the XText
> Documentation.
> import "link_to_model" as gruml
> import "link_to_model/domains" as domains
> import "link_to_model/structure" as structure (e.g.)
>
> This already seems to work, now the problem occurs, we want to also use
> an own grammar that is not equivalent to the emf model. Model and
> Grammar belong together in a very complicated way, but the rules will
> not generate the imported model. Now we started adding statements like:
> SchemaName returns structure::Schema:
> {name}
> packagePrefix=PackageName name=QualifiedName ';'
> ;
>
> to our grammar. As we are beginners in working with xtext,we now face a
> problem merging those two different parts into into project. Is there a
> possibility to merge them in a right way? Is Xtext capable of using a
> grammar and an imported model, that don't fit together?
> Don't ask why we need this, it is only important for us to get it
> working. We already read the documentation.
> Would be pleased if someone could help us :)
> Greetings
> Annika
Re: Combining existing Model and own Grammar [message #1005049 is a reply to message #1004199] Thu, 24 January 2013 11:29 Go to previous messageGo to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
Thanks for your quick answer!

Since we're beginnners in working with XText, we now wonder, what you mean by "perform
transformation in a build step". Is there a certain java class (like the ui-classes for outline etc) to be adjustet the way we want it to provide this "building functionality"? If you mean this, is there any tutorial or documentation where we can learn how to write such things? (or else, how is this done exactly? I think there is nearly no documentation about more difficult problems in Xtext...)

Is the "returns" functionality in the grammar a step towards the right solution?

Some background knowledge: Our grammar and our model both belong to the same language, but as they are used in different contexts (a visual editor and a textual editor) we need both representations. To build our grammar we used an existing EBNF and shortened it to the appropriate level. The model which is build in the background (not the emf-model but the one also responsible for the predefined outline view)should correspond to the EBNF. That's the reason why we coudn't create our grammar according to the EMF-Model, so that is automatically generated while building our editor. Now we have to merge them with our XText to provide a fluent workflow with both plugins we're working on.

Greetings,
Annika
Re: Combining existing Model and own Grammar [message #1005214 is a reply to message #1005049] Thu, 24 January 2013 16:49 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-24-01 12:29, Annika Wießgügel wrote:
> Thanks for your quick answer!
> Since we're beginnners in working with XText, we now wonder, what you
> mean by "perform
> transformation in a build step". Is there a certain java class (like the
> ui-classes for outline etc) to be adjustet the way we want it to provide
> this "building functionality"? If you mean this, is there any tutorial
> or documentation where we can learn how to write such things? (or else,
> how is this done exactly? I think there is nearly no documentation about
> more difficult problems in Xtext...)
>
The "builds" are eclipse workspace builds with a small extension to make
them easy to use with Xtext. In addition to the "build when files are
saved", you can naturally keep things in sync also while editing -
depends on when you want the other resources updated/synced.

Model to Model transformation is either done with your own java logic,
translating one EMF model into another, or by using one of the (many
different) model to model transformation frameworks available.

> Is the "returns" functionality in the grammar a step towards the right
> solution?
Yes, you will need (and want) to specify what rules return.

> Some background knowledge: Our grammar and our model both belong to the
> same language, but as they are used in different contexts (a visual
> editor and a textual editor) we need both representations. To build our
> grammar we used an existing EBNF and shortened it to the appropriate
> level. The model which is build in the background (not the emf-model but
> the one also responsible for the predefined outline view)should
> correspond to the EBNF. That's the reason why we coudn't create our
> grammar according to the EMF-Model, so that is automatically generated
> while building our editor. Now we have to merge them with our XText to
> provide a fluent workflow with both plugins we're working on.
> Greetings, Annika

Not sure I completely understood that.

If you are new to Xtext maybe you want to contract Itemis to help you
out - maybe just to get you on the right track. It may take you some
time to get familiar with all the involved technologies and find the
right approach.

Best of luck
Regards
- henrik
Re: Combining existing Model and own Grammar [message #1006471 is a reply to message #1005214] Thu, 31 January 2013 12:31 Go to previous messageGo to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
Thanks for trying to help us!

One more question, since the last post didn't help that much:
Is there a possibility to "skip" certain rules in the grammar?
For example you have a rule ThisRule and a rule ThatRule and you want to use an Ecore-Model that only has ThatRule but not ThisRule, but in your grammar you explicitly need ThisRule. Is there a possibility to say "thisRule does not correspond to anything in the ecore model, please skip it, continuing on ThatRule" ?

We now have this problem, since in our model (and the visual editor) we don't have a part that is included in our grammar. In the grammat it is essential and represents the document as a whole, so to say the whole model... We cannot transform it in any way...

Greetings,

Annika
Re: Combining existing Model and own Grammar [message #1006565 is a reply to message #1006471] Thu, 31 January 2013 18:59 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-31-01 13:31, Annika Wießgügel wrote:
> Thanks for trying to help us!
> One more question, since the last post didn't help that much: Is there a
> possibility to "skip" certain rules in the grammar?

Not really, although you can write rules that have no assignments you
will always end up with some kind of production of a result. The problem
is where this result is "added to its parent" if it is of a type that is
not supported.

Maybe write your grammar for a model that is derived from the original.
In this model you add the classes you need. If these classes only
contain things from the original grammar (and you don't have to assign
new things to old) then it should be quite easy to achieve.

It sounds like that is the case for you; some kind of top level
container that simply has content from the other model.

Hope that helps
- henrik

> For example you have
> a rule ThisRule and a rule ThatRule and you want to use an Ecore-Model
> that only has ThatRule but not ThisRule, but in your grammar you
> explicitly need ThisRule. Is there a possibility to say "thisRule does
> not correspond to anything in the ecore model, please skip it,
> continuing on ThatRule" ?
> We now have this problem, since in our model (and the visual editor) we
> don't have a part that is included in our grammar. In the grammat it is
> essential and represents the document as a whole, so to say the whole
> model... We cannot transform it in any way...
> Greetings,
> Annika
Re: Combining existing Model and own Grammar [message #1021915 is a reply to message #1006565] Wed, 20 March 2013 23:17 Go to previous message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
Thanks for all your help, we now had to quit the way of working, but our model-problem was solved by a kind of container-Model, a simple EMF-Model containing only those rules we needed to "skip". I suppose it was what you wanted us to do Smile
Previous Topic:document flyout missing on imports
Next Topic:JvmType, add additional Types, that will be generated, but are not there YET
Goto Forum:
  


Current Time: Fri Apr 19 14:06:34 GMT 2024

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

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

Back to the top