Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dealing with cross-reference instances(How to create or work with instances of a cross-referenced type)
Dealing with cross-reference instances [message #1806739] Tue, 14 May 2019 14:15 Go to next message
Markus Jakobsen is currently offline Markus JakobsenFriend
Messages: 2
Registered: May 2019
Junior Member
Hi,

I'm working on a GUI language, and find myself a little stuck when implementing a templating system for it. What I want to achieve is to define a custom/composite type of entity (template) and then instantiating this entity and assigning each instance different values. I've created a simplified version of my xtext file, but I believe it still captures the issue well. The two methods of overwriting the title value should ideally be interchangeable, and I can (with a lot of messing about) currently get the nested example (instanceOne) to work as described.

I've made the scoping work for the most part by adding local qualified names, but when I attempt to reference instanceTwo.title, all I get is effectively B.title, and no apparent way to distinguish between which instance it is (instanceOne.title === instanceTwo.title).

I suspect part of the problem originates from the fact that the properties are not owned by the entity, but that is a design constraint.

Now, is it possible to "instantiate" a type from a cross-reference, or perhaps something similar?

I greatly appreciate any thoughts on how to approach this problem!

Xtext file:
Model:
	main=Main?
	templates+=Template*
;
Main returns Unit:
	{Main} 'main' name=ID '{'
		'entities' '{' entities+=Entity* '}'
		('specifications' '{' specifications+=Specification* '}')?
	'}'
;
Template returns Unit:
	{Template} 'template' name=ID '{'
		'entities' '{' entities+=Entity* '}'
		('specifications' '{' specifications+=Specification* '}')?
	'}'
;
Entity:
	(
		{Label} 'label' |
		{Instance} 'new' ref=[Unit | ID]
	) name=ID 
;
Specification:
	entity=[Entity | FQN] '{' options+=Option* '}'
;
Option:
	{Text} 'text' '=' value=STRING |
	{InstanceOption} specification=Specification
;
FQN:
	ID ('.' ID)*
;


.mydsl example
main A {
	entities {
		label header
		B instanceOne
		B instanceTwo
	}
	specifications {
		header {
			text = "hello world"
		}
		instanceOne {
			title {
				text = "This is instance one"
			}
		}
		instanceTwo.title {
				text = "This is instance two"
			}
		}
	}
}

template B {
	entities {
		label title 
		label subtitle
	}
}



Cheers,
Markus
Re: Dealing with cross-reference instances [message #1806750 is a reply to message #1806739] Tue, 14 May 2019 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi. If you want to keep going this way you need to collect the objects
And adding them under the name you want to an explicit scope.

You might have a look at dot/path expressions as well
It's a more usual / general way of solving such problems

https://www.dietrich-it.de/xtext/2013/05/18/xtext-and-dot-expressions.html


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Dealing with cross-reference instances [message #1806804 is a reply to message #1806750] Wed, 15 May 2019 10:34 Go to previous message
Markus Jakobsen is currently offline Markus JakobsenFriend
Messages: 2
Registered: May 2019
Junior Member
Thanks. That looks interesting! I'll see if that works.
Previous Topic:Name conflicts while renaming
Next Topic:Completeness of the .ecore generated by Xtext
Goto Forum:
  


Current Time: Thu Mar 28 14:17:15 GMT 2024

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

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

Back to the top