Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Declare and implement ecore model import in xtext grammar (How to declare and implement ecore model import xtext grammar instances)
Declare and implement ecore model import in xtext grammar [message #1836971] Wed, 20 January 2021 07:08 Go to next message
Eclipse UserFriend
I have declared an xtext grammar:

grammar de.mdsd.GeneratorModel with org.eclipse.xtext.common.Terminals

generate generatorModel "http://www.mdsd.de/GeneratorModel"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

GeneratorModel:
	importList+=Import*
	"generator" "model" name=ID "for" model=[ecore::EPackage]
	(
		namedFeatureList+=NamedFeatureReference 
		| generatorList+=Generator
	)*
	;

Import:
	"import" referencedModel+=[ecore::EPackage|STRING]
;
...


The grammar compiles fine.

I declared an Instance of this grammar:

//import "GeneratorModelGenerator"  // was a suggestion from the auto completion
//import "GeneratorModel"
//import "http://www.mdsd.de/GeneratorModel" // this is the grammars own URI
//import "platform:/resource/de.mdsd.generator.model/model/generated/GeneratorModel.genmodel" // genmodel location in the project
import "platform:/resource/de.mdsd.generator.model/model/generated/GeneratorModel.ecore" // ecore model location in the project
generator model GeneratorModelGenerator for GeneratorModel
...


but neither import works.

How I have to note the import declaration in the grammar instance.
Which other declaration I have to implement getting the Scope right thus the instance can find an load the imported model.
I have searched the web a lot but did not find a complete instruction how to handle grammar imports with Xtext 2.24.
It seems importing does not work out of the box like it does in former versions of Xtext.
It is no error that I try to import the grammars model here, it is like a bootstrap in this case.
A pointer to a complete tutorial would just be fine.
Re: Declare and implement ecore model import in xtext grammar [message #1836972 is a reply to message #1836971] Wed, 20 January 2021 07:16 Go to previous messageGo to next message
Eclipse UserFriend
import "http://www.mdsd.de/GeneratorModel"
should work perfectly fine if ecore containing project has xtext nature
you then need to add a referencedResource="platform:/resource/project/path/xxx.genmodel" entry to the language section of the workflow
Re: Declare and implement ecore model import in xtext grammar [message #1836978 is a reply to message #1836972] Wed, 20 January 2021 08:58 Go to previous message
Eclipse UserFriend
Hi

That will work if you only use Xtext tooling, but if you want to use other tools, such as an M2M that is Xtext-nature-blind, to process your *,xtext you will need something like

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/org.eclipse.ocl.pivot/model/Pivot.ecore" as pivot


where the first import is for something guaranteed to be Java code in a plugin and the second is for the Ecore fle probably in a project.

You will need to set the Xtext project preference to ignore warnings about models not imported by nsURI.

Using this form of import and if your MWE2 scripts are in a distinct plugin, your plugin does not need the Xtext nature at all saving on unnecessary build effort.

Regards

Ed Willink
Previous Topic:Xtend: Any way to show javadoc of super-method in hover?
Next Topic:Java LSP client for Xtext Language Server?
Goto Forum:
  


Current Time: Fri Jul 04 12:55:41 EDT 2025

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

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

Back to the top