Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Automatically generate XText grammar from UML Profile in Papyrus
Automatically generate XText grammar from UML Profile in Papyrus [message #1834660] Sat, 14 November 2020 19:00 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Ok, so here I have uploaded my UML profile. I am trying to automatically generate a XText grammar for it.

The steps I follow to generate the XText grammar are as follows:

Step 1
New -> Other -> EMF Generator Model
Filename:corona.genmodel
Model Importers: UML Model
Model URIs: platform:/resource/Corona/Corona.profile.uml

Root Packages: Corona
References generator models: ECore, Types, UML
Finish

Step 2
Right click on the project -> Configure-> Convert to Xtext Project

Step 3
New -> XText Project from existing ecore models
Add EPackages (corona.genmodel - /Corona)
Entry Rule: WorldMap Corona
Finish

When I do it this way, in the new generated grammar I have issues such as:
Line 15
Multiple markers at this line
- Couldn't resolve reference to EClassifier 'EString'.
- extraneous input '|' expecting RULE_ID

Line 19
Multiple markers at this line
- Cannot create type 'EDataType' in alias null
- The rule 'EDataType' may be consumed without object instantiation.
Add an action to ensure object creation, e.g. '{null}'.
- missing RULE_ID at ':'

The result I get from debugging is:

0    [main] INFO  text.xtext.generator.XtextGenerator  - Initializing Xtext generator
9    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.common.types.TypesPackage'
100  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.xtext.example.mydsl2 at 'file:/Users/mlj01/eclipse-workspace/org.xtext.example.mydsl2/'
100  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.xtext.example.mydsl2.tests at 'file:/Users/mlj01/eclipse-workspace/org.xtext.example.mydsl2.tests/'
100  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.xtext.example.mydsl2.ide at 'file:/Users/mlj01/eclipse-workspace/org.xtext.example.mydsl2.ide/'
100  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.xtext.example.mydsl2.ui at 'file:/Users/mlj01/eclipse-workspace/org.xtext.example.mydsl2.ui/'
100  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering project org.xtext.example.mydsl2.ui.tests at 'file:/Users/mlj01/eclipse-workspace/org.xtext.example.mydsl2.ui.tests/'
106  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Using resourceSet registry. The registered Packages will not be registered in the global EPackage.Registry.INSTANCE!
247  [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow org.xtext.example.mydsl2.GenerateMyDsl: java.io.IOException: The path '/Corona/corona.genmodel' is unmapped
java.lang.RuntimeException: Problems running workflow org.xtext.example.mydsl2.GenerateMyDsl: java.io.IOException: The path '/Corona/corona.genmodel' is unmapped
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:105)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:63)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:53)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:79)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:37)
Caused by: org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.io.IOException: The path '/Corona/corona.genmodel' is unmapped
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:266)
	at org.eclipse.xtext.xtext.generator.XtextGeneratorResourceSetInitializer.loadResource(XtextGeneratorResourceSetInitializer.java:52)
	at org.eclipse.xtext.xtext.generator.XtextGeneratorResourceSetInitializer.lambda$initialize$0(XtextGeneratorResourceSetInitializer.java:42)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.eclipse.xtext.xtext.generator.XtextGeneratorResourceSetInitializer.initialize(XtextGeneratorResourceSetInitializer.java:44)
	at org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage.initialize(XtextGeneratorLanguage.java:219)
	at org.eclipse.xtext.xtext.generator.StandardLanguage.initialize(StandardLanguage.java:192)
	at org.eclipse.xtext.xtext.generator.XtextGenerator.initialize(XtextGenerator.java:186)
	at org.eclipse.xtext.xtext.generator.XtextGenerator.checkConfigurationInternal(XtextGenerator.java:140)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2.checkConfiguration(AbstractWorkflowComponent2.java:23)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.preInvoke(Mwe2Bridge.java:69)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.preInvoke(AbstractWorkflowComponent.java:208)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.preInvoke(AbstractCompositeWorkflowComponent.java:31)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:20)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:103)
	... 4 more
Caused by: java.io.IOException: The path '/Corona/corona.genmodel' is unmapped
	at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createInputStream(PlatformResourceURIHandlerImpl.java:578)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:358)
	at org.eclipse.xtext.resource.XtextResourceSet$1.createInputStream(XtextResourceSet.java:299)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1314)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	... 19 more

  • Attachment: Corona.zip
    (Size: 11.40KB, Downloaded 54 times)
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834670 is a reply to message #1834660] Sun, 15 November 2020 12:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Thanks. Now I can see what you are doing and play with it in my workspace.

(It is strongly recommended that models are moved from the root to a model folder.)

It is intriguing to see this use case nearly working. I was unaware that Xtext had this Ecore2Xtext capability. I must confess that I see it more as a toy since the whole purpose of a DSL is to provide something friendly to the user rather than yet another mindless serialization that is probably rather similar to HUTN.

Anyway there are clearly bugs, probably triggered by perhaps no one having ever tried this for UML before. It clearly is not subject to JUnit testing as part of the Xtext release else the missing

import "http://www.eclipse.org/uml2/5.0.0/Types" as types

that is necessary for UML 2.5 (since 2014) would be present. Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=568819 raised.

The bad EDataType0 is traceable to

CountryCorona returns Corona::CountryCorona:
'CountryCorona'
'{'
'population' population=EDataType
'continent' continent=EDataType0
'infectedPopulation' infectedPopulation=EDataType1
'zonelabel' zonelabel=zonelabelcolour
('base_Component' base_Component=[uml::Component|EString])?
'}';

which comes from the Ecore/UML where continent has a built-in String type.

Clearly the Ecore2Xtext converter lacks the ability to detect that String has a java.lang.String representation that can be reified as an EString. It is a moot point whether this is a missing conversion option in UML2Ecore used by EMF's GenModel or a missing EDataType inspection in Ecore2Xtext.

If you select the Ecore::EInt and Ecore::EString types, no magic conversion is necessary and your auto-generated Xtext has just one error; the missing types import.

However you can really just be grateful that Ecore2Xtext has created a 99.9% correct grammar that you can easily fix up by hand. As soon as you start using the grammar you will find it unacceptably verbose and klunky.

Surely your users want to type

... < ... , ... > ...

rather than

... templateBinding { ... , ... } ...

Regards

Ed Willink
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834676 is a reply to message #1834670] Sun, 15 November 2020 14:41 Go to previous messageGo to next message
Malvina Latifaj is currently offline Malvina LatifajFriend
Messages: 11
Registered: June 2020
Junior Member
No Message Body

[Updated on: Sun, 15 November 2020 14:42]

Report message to a moderator

Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834677 is a reply to message #1834670] Sun, 15 November 2020 14:42 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Ed,

Thank you for the explanation. Yeah I am trying this out because I want to understand what is the best grammar I can get from an automatic generation and how much do I need to change manually.

Regarding import "http://www.eclipse.org/uml2/5.0.0/Types" as types, that would be present only if I would also select it as a root package and not reference it from other generator models. However, if I do that I get a lot of information regarding UML in my grammar which I do not need it.

Just one question, what do you mean by "select" the Ecore::EInt and Ecore::EString types
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834678 is a reply to message #1834677] Sun, 15 November 2020 17:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

UML 2.5 separated off the Types Package to solve a variety of re-use problems. You will find yourself pretty dead in the water unless you import it.

I select the Ecore::EInt type in the Properties View of the UML Model Editor by clicking on the type feature so that a very long list of every possible type appears. I am sure that the Papyrus editor has a similar capability. (Same place where you might change String to Boolean.)

Regards

Ed Willink
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834682 is a reply to message #1834678] Sun, 15 November 2020 19:47 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Yeah, I was able to fix that. Many thanks.

Do you think the same can be done with classes and packages?
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834685 is a reply to message #1834670] Sun, 15 November 2020 22:07 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
I tried this approach by creating a model in XText with my grammar. The thing is that when XText should provide as a suggestion the EString or the EInt, it does not provide it. I am now trying to understand why, but nevertheless I do not think this approach will do the trick.
Re: Automatically generate XText grammar from UML Profile in Papyrus [message #1834689 is a reply to message #1834685] Mon, 16 November 2020 06:01 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Neither of your last two comments make any sense to me, so I cannot respond.

Regards

Ed Willink
Previous Topic:Couldn't resolve reference to EPackage
Next Topic:Can Ecore::EString be used in XText?
Goto Forum:
  


Current Time: Thu Mar 28 18:27:23 GMT 2024

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

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

Back to the top