Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar for ecore metamodel
grammar for ecore metamodel [message #1235063] Thu, 23 January 2014 13:32 Go to next message
Andras Kovi is currently offline Andras KoviFriend
Messages: 13
Registered: January 2014
Junior Member
I'm looking for a complete grammar for the ecore metamodel. Would be great to edit ecore models with a DSL. I need to create an ecore model, not a metamodel that is instantiated at a later time. Does there exist such a project?

I want to use the ecore models this way:

Registry::INSTANCE.extensionToFactoryMap.put("ecore", new EcoreResourceFactoryImpl)
val classUrl = Generator.classLoader.getResource(modelPath)
val resource = new XMIResourceImpl()
resource.load(file.openStream, new Attributes())

resource.allContents() // this is where the party begins

emfatic (http://www.eclipse.org/epsilon/doc/articles/emfatic/) is an interesting solution but the transformation from-to ecore was not always performed when I tried.

Thanks,
Andras
Re: grammar for ecore metamodel [message #1235081 is a reply to message #1235063] Thu, 23 January 2014 14:36 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Xcore
Re: grammar for ecore metamodel [message #1235086 is a reply to message #1235063] Thu, 23 January 2014 14:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The thing you are looking for is called Xcore, isn't it?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar for ecore metamodel [message #1235388 is a reply to message #1235063] Fri, 24 January 2014 08:06 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Several people have mentioned Xcore, which is a grammar for a model that
is slightly different than Ecore. When loading an Xcore file (into a
resource set), a correponding Ecore model (and a genmodel) is
automatically computed/derived. This model is stored in an EPackage
object in the resource's contents and can be retrieved and processed for
your own purpose. So in practice you can regard Xcore as ecore.

Hallvard

On 23.01.14 15:30, Andras Kovi wrote:
> I'm looking for a complete grammar for the ecore metamodel. Would be
> great to edit ecore models with a DSL. I need to create an ecore model,
> not a metamodel that is instantiated at a later time. Does there exist
> such a project?
>
> I want to use the ecore models this way:
> Registry::INSTANCE.extensionToFactoryMap.put("ecore", new
> EcoreResourceFactoryImpl)
> val classUrl = Generator.classLoader.getResource(modelPath)
> val resource = new XMIResourceImpl()
> resource.load(file.openStream, new Attributes())
>
> resource.allContents() // this is where the party begins
>
> emfatic (http://www.eclipse.org/epsilon/doc/articles/emfatic/) is an
> interesting solution but the transformation from-to ecore was not always
> performed when I tried.
>
> Thanks,
> Andras
Re: grammar for ecore metamodel [message #1236942 is a reply to message #1235388] Tue, 28 January 2014 13:03 Go to previous messageGo to next message
Andras Kovi is currently offline Andras KoviFriend
Messages: 13
Registered: January 2014
Junior Member
Exactly, thank you Hallvard. Xcore is simplified compared to the Ecore metamodel.

I need a complete Ecore model textual editor. My domain model is the Ecore metamodel.

I tried to create an Xtext editor using the automatic "Xtext from ecore model feature" as described here http:// blog.efftinge.de/2009/11/xtext-using-existing-ecore-models.html Unfortunately, this resulted in a severely crippled model (some 4 elements only) that is nothing near to what I would expect.

Thank you,
Andras
Re: grammar for ecore metamodel [message #1237109 is a reply to message #1236942] Tue, 28 January 2014 22:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You will find that the (Xtext) OCLinEcore editor is a superset of a much
more complete Ecore grammar.

Regards

Ed Willink


On 28/01/2014 13:03, Andras Kovi wrote:
> Exactly, thank you Hallvard. Xcore is simplified compared to the Ecore
> metamodel.
>
> I need a complete Ecore model textual editor. My domain model is the
> Ecore metamodel.
>
> I tried to create an Xtext editor using the automatic "Xtext from
> ecore model feature" as described here http://
> blog.efftinge.de/2009/11/xtext-using-existing-ecore-models.html
> Unfortunately, this resulted in a severely crippled model (some 4
> elements only) that is nothing near to what I would expect.
>
> Thank you,
> Andras
Re: grammar for ecore metamodel [message #1237124 is a reply to message #1237109] Tue, 28 January 2014 23:12 Go to previous messageGo to next message
Andras Kovi is currently offline Andras KoviFriend
Messages: 13
Registered: January 2014
Junior Member
Fabulous, thank you Ed! It seems to support almost everything I need. Almost because references in annotations are not supported (similarly to emfatic). My model extensively uses this feature because this is actually the only way to add Java-like real annotations to elements. Anything else is just String, not a reference that I can count on while processing the model.

For example, if I want to note that a class must not be used in generator A, then I can add an annotation with reference to the IgnoredInA enum value. I could do it with strings too but who is going to ensure that I did not mistype the word? And what if I need to add multiple references?

So the question is: Is there any way I could use references for annotations with the OCLinEcore editor? Would it be possible to add this feature?

I think this is a really strong feature in Ecore and I'm surprised that it is not used more often. Or there may be some other way I am not aware of. If this is the case, I'd be extremely happy to learn about it.
Re: grammar for ecore metamodel [message #1237226 is a reply to message #1237124] Wed, 29 January 2014 07:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I don't fully understand your comment; references in annotations.

I have gradually fixed support for obscure areas so that support is
almost complete. EGenericType bounds are missing. EAnnotation support
has improved but before Kepler; the only EAnnotation reference
limitation I am aware of is that the target must be a known
EModelElement rather than an arbitrary EObject - perhaps a fall-back
proxy syntax is needed.

NB the grammar

AnnotationCS returns base::AnnotationCS:
{base::AnnotationCS} 'annotation'
name=(UnrestrictedName|SINGLE_QUOTED_STRING)?
('(' ownedDetail+=DetailCS (',' ownedDetail+=DetailCS)* ')')?
(('{' (ownedAnnotation+=AnnotationElementCS
| ownedContent+=ModelElementCS
| ownedReference+=ModelElementRefCS
)+'}')
|';'
)
;

is clearly trying to do references.

Regards

Ed Willink

On 28/01/2014 23:12, Andras Kovi wrote:
> Fabulous, thank you Ed! It seems to support almost everything I need.
> Almost because references in annotations are not supported (similarly
> to emfatic). My model extensively uses this feature because this is
> actually the only way to add Java-like real annotations to elements.
> Anything else is just String, not a reference that I can count on
> while processing the model.
>
> For example, if I want to note that a class must not be used in
> generator A, then I can add an annotation with reference to the
> IgnoredInA enum value. I could do it with strings too but who is going
> to ensure that I did not mistype the word? And what if I need to add
> multiple references?
>
> So the question is: Is there any way I could use references for
> annotations with the OCLinEcore editor? Would it be possible to add
> this feature?
>
> I think this is a really strong feature in Ecore and I'm surprised
> that it is not used more often. Or there may be some other way I am
> not aware of. If this is the case, I'd be extremely happy to learn
> about it.
Re: grammar for ecore metamodel [message #1237322 is a reply to message #1237226] Wed, 29 January 2014 11:59 Go to previous messageGo to next message
Andras Kovi is currently offline Andras KoviFriend
Messages: 13
Registered: January 2014
Junior Member
Great, thank you! The model I tried did not show this syntax. I got it working with a minimalistic model:

package model : model = 'http://eclipse.org/myModel'
{
	enum Annotations { serializable }
	{
		literal IgnoreInA;
		literal IgnoreInB = 1;
	}
	class TryClass
	{
		annotation Source
		{
			reference _'#//Annotations/IgnoreInA';
			reference TryClass;
		}
		attribute attrib1 : String[?];
	}
}

I still may have a few questions, though:

1. Negative values for literals (and generally for Integers) do not seem to work. So
literal IgnoreInB = -1;
is an error.

2. The contents of the ecore file (and the internal model too) get lost if save is used on an invalid model. The contents of that editor will not be saved anymore either. Fortunately, the Eclipse local history exists as a savior but this resets to a previous state which is not ideal. Smile

3. Classes are resolved correctly in references but literal references are shown as strings. Would it be possible to make them uniformly resolved?

If there is a solution for 1., this would be the perfect tool. The other ones are only nuisances.

Regards,
Andras

PS for future reference I found the code you are referring to: http://git.eclipse.org/c/mdt/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.xtext.oclinecore/src/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xtext

[Updated on: Wed, 29 January 2014 12:02]

Report message to a moderator

Re: grammar for ecore metamodel [message #1237424 is a reply to message #1237322] Wed, 29 January 2014 17:36 Go to previous message
Andras Kovi is currently offline Andras KoviFriend
Messages: 13
Registered: January 2014
Junior Member
After a discussion with Ed Willink I created bugs

Minimize reference qualification https://bugs.eclipse.org/bugs/show_bug.cgi?id=426929
Resolve Enum literals in references https://bugs.eclipse.org/bugs/show_bug.cgi?id=426927

The errors mentioned in the previous post were the result of some misconfiguration/bad constellation of plugins. A clean installation of eclipse solved most of them. The OCLinEcore editor is definitely an answer for this topic. Unfortunately, stability issues arise pretty fast as the model size grows, but these are most probably originating from the xtext base. Further research is needed on the problems.
Previous Topic:antlr error with the workflow file
Next Topic:Grammar and Validation unit_testing
Goto Forum:
  


Current Time: Fri Apr 19 04:04:29 GMT 2024

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

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

Back to the top