Importing a Metamodel in XText 2.12. [message #1774868] |
Fri, 20 October 2017 17:27 |
Ruchika Kumar Messages: 50 Registered: January 2017 |
Member |
|
|
Hello,
I tried by all means for the last two days to find a post that would allow me to solve my problem, but alas here I am.
The problem I'm trying to fix is simple enough: I'm trying to import an ecore metamodel in XText instead of generating it. Resources such as this and others seem to be deprecated for XText 2.12
Unfortunately, the proposed solution online seem to be deprecated. Therefore, I opted to follow the instructions in the XText documentation, namely the section for importing metamodels, by creating the default XText "MyDsl" project.
MyDsl.text:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
GenerateMyDsl.mwe2:
module org.xtext.example.mydsl.GenerateMyDsl
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "org.xtext.example.mydsl"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "windows-1252"
lineDelimiter = "\r\n"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}
As expected, after generating the XText artifacts, I get a MyDsl.ecore and MyDsl.genmodel written in "./model/generated".
I then proceeded to change the "generate" statement to an "import" in MyDsl.text:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
And registered my "MyDsl.genmodel", as explained in documentation through the workflow file GenerateMyDsl.mwe2:
module org.xtext.example.mydsl.GenerateMyDsl
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "org.xtext.example.mydsl"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "windows-1252"
lineDelimiter = "\r\n"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
//added this line
referencedResource = "platform:/resource/org.xtext.example.mydsl/model/temp/MyDsl.genmodel"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}
The "./model/temp" folder is just a copy of "./model/generated". I then go on to successfully generate the XText artifacts once again, but some of the generated artifacts contain compilation errors, namely some manifest files complaining "org.xtext.example.mydsl.myDsl.impl,
org.xtext.example.mydsl.myDsl" do not exist in this plug-in.
My intuition tells me this problem has something do to with registering an ePackage for the meta model, but I'm not sure exactly how to go about that.
Is there a quick fix that can be made so that I can import an ecore metamodel file in XText?
In case it factors in the analysis, I'm currently using XText 2.12 and Eclipse Oxygen
Thanks in advance
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03534 seconds