Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Loading file-based ecore files from xText DSML
Loading file-based ecore files from xText DSML [message #1776443] Thu, 16 November 2017 13:33 Go to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
Hi all,

I'm trying to do something similar to the core xtext grammar where it allows referencing an external Ecore package through a URL and then use the imported classifiers etc. within the remaining model.

So, I have something like this in my grammar:

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

...

A:
	s = [ecore::EPackage | STRING]  t = [ecore::EPackage | STRING] "{"
		bs += B+ 
	"}"
;

B:
	s = [ecore::EClassifier | QualifiedName] "=>" t = [ecore::EClassifier | QualifiedName]
;


Eventually, I want to define a scope such that B.s can be filled with classifiers from the containing A.s and B.t can be filled with classifiers from the containing A.t.

I have been googling about, reading documentation on scoping etc and scanning through the XText sources, too. I think I understand how to define the local scope for B.s and B.t. However, at the moment, I cannot figure out how to get A.s and A.t to load the correct .ecore file. Note that in my case these Ecore models are not registered, so I need to provide a file path. However, in my test, even when I provide a platform URL for it, Xtext doesn't load it.

My test example parses OK and does not produce any errors. However, in the model created, all I get is proxies for all the Ecore bits, with strange IDs such as "eProxyURI: __synthetic0.lang_compose#|0".

I'm clearly missing something here, but cannot figure out what. Any thoughts? I know about global scope providers, but given that Xtext can already do this when parsing grammars, I assume that this would either work out of the box or that there would be a GlobalScopeProvider I can reuse for this. Unfortunately, I couldn't find one.

Many thanks,

Steffen
Re: Loading file-based ecore files from xText DSML [message #1776444 is a reply to message #1776443] Thu, 16 November 2017 13:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi,

how do you "test" your dsl?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Loading file-based ecore files from xText DSML [message #1776445 is a reply to message #1776444] Thu, 16 November 2017 13:42 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
I've written a test in the standard test project generated by xtext:

@RunWith(XtextRunner)
@InjectWith(XFooInjectorProvider)
class XFooParsingTest {
	@Inject
	ParseHelper<A> parseHelper
	
	@Test
	def void loadModel() {
		val result = parseHelper.parse('''
			"platform:/some_project/some_path/s.ecore" "platform:/some_project/some_path/t.ecore" {
					s.S => t.T
			}
		''')
		Assert.assertNotNull("Did not produce parse result", result)
		Assert.assertTrue("Found parse errors: " + result.eResource.errors, result.eResource.errors.isEmpty)
		Assert.assertNotNull("Did not load s classifier", result.bs.head.s.name)
	}
}


It fails at that last assert statement
Re: Loading file-based ecore files from xText DSML [message #1776447 is a reply to message #1776445] Thu, 16 November 2017 14:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
you need to somehow make sure the standalone ecore support is in places e.g. with the classes /org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreSupport.java or /org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreSupportStandaloneSetup.java

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Loading file-based ecore files from xText DSML [message #1776448 is a reply to message #1776447] Thu, 16 November 2017 14:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and of course the platform:/resource uris wont work in standalone mode as well.
=> have a look at the standalone class and its options to set a platformUri, scanclasspath or add project mappings


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Loading file-based ecore files from xText DSML [message #1776449 is a reply to message #1776448] Thu, 16 November 2017 14:10 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
I see. I had started to think that using platform URIs would be part of the problem, so I have switched to the version of parse that uses an explicit resource set and am providing it with one that I prepare by pre-loading the two ecore files. I guess, now I just need to add the support for EcoreSupport. Any suggestions about where I should add these in?
Re: Loading file-based ecore files from xText DSML [message #1776458 is a reply to message #1776449] Thu, 16 November 2017 15:02 Go to previous message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
Figured it out, many thanks. The solution was to add the registration of EcoreSupport into the StandaloneSetup#register as shown here: https://searchcode.com/codesearch/view/37962746/

Now on to narrowing those scopes so that they really only can refer to members of the files referenced
Previous Topic:Sharing how to override the lexer
Next Topic:Two DSL in same project
Goto Forum:
  


Current Time: Thu Mar 28 20:04:04 GMT 2024

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

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

Back to the top