Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problems with generated grammar from existing ecore model
Problems with generated grammar from existing ecore model [message #759881] Wed, 30 November 2011 13:22 Go to next message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
I am new to Xtext and interested in using it for an existing ecore model as a textual editor. As explained in the blog entry http://blog.efftinge.de/2009/11/xtext-using-existing-ecore-models.html this should be possible. Also, I found it very interesting to let the user decide whether to use the textual or standard generated EMF editor.

Using Xtext version (2.0.1) I used the "Xtext Project From Existing Ecore Models" project wizard and pointed to the EMF library.genmodel.

After generating the textual editor I tried opening the file with the EMF reflective editor and added an author, a book and then saved. The serialized textual version looked ok.

After setting the book relation from the author in the EMF reflective editor and then saving I got the below exception.

Is this a bug in the generated grammar?

I got another problem using the grammar in Sven's blog entry when trying to save a change from the EMF reflective editor.

Regards,

Anders Forsell

---

org.eclipse.xtext.parsetree.reconstr.XtextSerializationException: Could not serialize cross reference from Library'MyLibrary'.writers[0]->Writer'Author1'.books to Library'MyLibrary'.books[0]->Book
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$AssignmentToken.serializeInternal(AbstractParseTreeConstructor.java:258)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$AbstractToken.serialize(AbstractParseTreeConstructor.java:159)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:772)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:767)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:767)
at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:733)
at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:56)
at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:62)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:286)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.saveOnlyIfChangedWithMemoryBuffer(ResourceImpl.java:1137)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:978)
at org.eclipse.emf.ecore.presentation.EcoreEditor$11.execute(EcoreEditor.java:1465)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Re: Problems with generated grammar from existing ecore model [message #759947 is a reply to message #759881] Wed, 30 November 2011 16:29 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Anders,

the exception indicates that the model is not valid according to the
grammar that you specified.
Consider the following example:

Person:
fullName = STRING
| firstName = STRING lastName = STRING;


This parser rule implies that a valid instance of Person has either an
assigned fullName (where firstName and lastName are unassigned) or the
fullName is unassigned but firstName and lastName are assigned.

The reference documentation contains plenty of information on how to
decide which models are valid and which aren't.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.11.11 14:22, schrieb Anders Forsell:
> I am new to Xtext and interested in using it for an existing ecore model
> as a textual editor. As explained in the blog entry
> http://blog.efftinge.de/2009/11/xtext-using-existing-ecore-models.html
> this should be possible. Also, I found it very interesting to let the
> user decide whether to use the textual or standard generated EMF editor.
>
> Using Xtext version (2.0.1) I used the "Xtext Project From Existing
> Ecore Models" project wizard and pointed to the EMF library.genmodel.
>
> After generating the textual editor I tried opening the file with the
> EMF reflective editor and added an author, a book and then saved. The
> serialized textual version looked ok.
>
> After setting the book relation from the author in the EMF reflective
> editor and then saving I got the below exception.
>
> Is this a bug in the generated grammar?
>
> I got another problem using the grammar in Sven's blog entry when trying
> to save a change from the EMF reflective editor.
>
> Regards,
>
> Anders Forsell
>
> ---
>
> org.eclipse.xtext.parsetree.reconstr.XtextSerializationException: Could
> not serialize cross reference from
> Library'MyLibrary'.writers[0]->Writer'Author1'.books to
> Library'MyLibrary'.books[0]->Book
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$AssignmentToken.serializeInternal(AbstractParseTreeConstructor.java:258)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor$AbstractToken.serialize(AbstractParseTreeConstructor.java:159)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:772)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:767)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.write(AbstractParseTreeConstructor.java:767)
>
> at
> org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:733)
>
> at
> org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:56)
>
> at
> org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:62)
>
> at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:286)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.saveOnlyIfChangedWithMemoryBuffer(ResourceImpl.java:1137)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:978)
>
> at
> org.eclipse.emf.ecore.presentation.EcoreEditor$11.execute(EcoreEditor.java:1465)
>
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
>
> at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
> at
> org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
>
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
>
Re: Problems with generated grammar from existing ecore model [message #759984 is a reply to message #759947] Wed, 30 November 2011 19:17 Go to previous message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
I didn't provide the grammar, it was generated by the Wizard taking the library ecore model as input.

Is the generated grammar not supposed to be valid and complete?

Since the simple example has this problem both with the generated grammar and with Sven Efftinge's grammar from his blog, I am suspicious that there is some limitation with this approach.

For example, are bidirectional relations handled correctly?

Anders
Previous Topic:multiple generators - Xtext2, xtend2
Next Topic:Grammar question
Goto Forum:
  


Current Time: Wed Apr 24 22:44:11 GMT 2024

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

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

Back to the top