Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Instantiate elements without having them visible in the syntax
Instantiate elements without having them visible in the syntax [message #766116] Thu, 15 December 2011 08:50 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
It is a rather akward question but let me clarify this. Suppose that you have the following grammar:

generate componentDSL "http://www.fmtc.be/components/ComponentDSL"

Component:
	'component' name = ID '{'
		'inputs:' inPorts+=Port
		'outputs:' outPorts+=Port
	'}'	
;

Port:
	type=STRING name=ID interface=Interface
;

Interface:
	{Interface}
;


You can see that when a Port is created, an Interface instance is also created and assigned to the "interface" variable of Port.

Now, suppose that Interface also had a type, which should be equal to the type of Port. This type should automatically be assigned from the type of the parent (Port) without showing it in the syntax, so something like this:

Interface:
	{Interface}
	type="type of the parent Port"
;


Of course, this is not possible since the Interface rule might be used from another rule that Port. But, within the port rule, is it possible to assign the value of the Interface type ?

I know that the use case presented here is totally wrong, but I'm trying to see what is possible with Xtext.

Thank you.
Re: Instantiate elements without having them visible in the syntax [message #766193 is a reply to message #766116] Thu, 15 December 2011 10:46 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
If I understand correctly, you want the Interface type to have a feature (an EReference, in fact) which is automagically assigned the enclosing/parent Port, without that being explicit in the syntax?

Then the answer is no: during the parse, values (strings, references, etc.) are always assigned exactly once. In your case, I'd say you're better off with a util method/derived property which simply uses EMF .eContainer() to get hold of the parent Port and decorate any Interface with the correct type. Xtend with its extensions is perfectly suited for that. Also remember that while a set of types is derived from an Xtext grammar (when not using external EPackages), the main responsibility of a grammar is defining the syntax.


Previous Topic:Xtend debugger?
Next Topic:Formatting-Indent // Particular case
Goto Forum:
  


Current Time: Wed Apr 24 18:41:40 GMT 2024

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

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

Back to the top