Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross reference to a cross reference ??
icon5.gif  Cross reference to a cross reference ?? [message #1061454] Fri, 31 May 2013 13:34 Go to next message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
Hey guys,

I am very new to XText and creating DSLs, so I got stuck with a (for me) very complex problem.

I designed a DSL where you can define objects which are hierarchical structured and to decrease the workload for the user i want to make it possible to define an "abstract" object or a kind of template which the user can use inside this hierarchical structure.
So I implemented that you can make a reference to this template at the position where you want it to be filled in.

Therefore not the template itself should be an instance of the elements defined in it, but the reference to it.

This is for now not really a problem, I can make a reference to the template and at that position where the reference is defined the code generator should fill in everything what is defined in the template.

But my real problem is now that the elements in my hierarchy can have dependencies between eachother and so I need a reference to a particular element of the template, but of this particular instance.
So the formulation of the conditional expression is a reference to an childobject of this instance of the template which itself is only a reference to the template definition.

So how can I implement this?? I really hope that you understood my problem and you can help me!!

I am really happy about every answer and advice!
Re: Cross reference to a cross reference ?? [message #1061473 is a reply to message #1061454] Fri, 31 May 2013 15:57 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1151
Registered: July 2009
Senior Member
Hi,

"just" make sure that elements in the hierarchy that can be referred to have a name (even if technically they are references). If you could post a sample model, it might be easier to give more specific advice.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cross reference to a cross reference ?? [message #1061577 is a reply to message #1061473] Mon, 03 June 2013 02:21 Go to previous messageGo to next message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
Hey Alexander,

thanks for your fast reply!
If I understood you right, than you think I should just give the references a name. But if I do so I just can refer to the reference and still have no access to the child nodes/objects my reference refers to. Maybe it is still unclear want I want to do so I here is an example model and code. I hope it makes clearer what my requirements and problems are.

My metamodel looks like that:

Model:
        ...
        hierarchBody = HierarchBody
        ...
;

HierarchBody:
{HierarchBody}
name = 'HIERARCHY' 
element += HierarchyElement*
'END_HIERARCHY'
;

HierarchyElement:
Group | TemplateDefinition
;

Group:
'GROUP' name=ID 
elements += (GroupElement)+
'END_GROUP'
;

GroupElement:
Entity|TemplateReference|TemplateDefinition
;

Entity:
'ENTITY' name=ID 
value = Value
'END_ENTITY'
;

TemplateDefinition:
'define' 'template' name = ID '[' templatevariable=TemplateVariable ']'
elements += (Entity|TemplateReference)+
'end_define'
;

TemplateVariable:
name=ID
;

TemplateReference:
{TemplateReference}
name=ID 'references to' reference=[TemplateDefinition|ID] '[' elements=IntElementList ']'
;



And a example model code could look like this:

HIERARCHY
 define template TemplateOfEntities[Index]
  ENTITY TemplateEntity1
    value 47
  END_ENTITY
  ENTITY TemplateEntity2
    value 11
  END_ENTITY
 end_define

 GROUP Group1
  TemplateInjection1 references to TemplateOfEntities[1..5]

  TemplateInjection2 references to TemplateOfEntities[10..15]

  if(TemplateInjection1.TemplateEntity1.value == 47)
    ENTITY Entity1G1
     value 123
    END_ENTITY
  end_if
 END_GROUP

END_HIERARCHY
Re: Cross reference to a cross reference ?? [message #1062121 is a reply to message #1061577] Thu, 06 June 2013 02:21 Go to previous messageGo to next message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
Has nobody any hint for me? I really don't know how to solve this problem.
I would already be glad if someone could tell me which direct I have to go.
Do I have to change my model or do I have to solve it with scoping or....
Re: Cross reference to a cross reference ?? [message #1062130 is a reply to message #1062121] Thu, 06 June 2013 03:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6131
Registered: July 2009
Senior Member
Hi can you give a complete reproduce able example ?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
icon1.gif  Re: Cross reference to a cross reference ?? [message #1063776 is a reply to message #1062130] Fri, 14 June 2013 04:07 Go to previous messageGo to next message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
Hey Christian,
thanks for your reply and sorry that I am answering only now. I didn't get a automatically generated mail this time so I didn't recognize it.

So here is a functional example model:
grammar org.xtext.example.forum.FORUM with org.eclipse.xtext.common.Terminals

generate fORUM 

Model:
        hierarchBody = HierarchBody
;

HierarchBody:
{HierarchBody}
name = 'HIERARCHY' 
element += HierarchyElement*
'END_HIERARCHY'
;

HierarchyElement:
Group | TemplateDefinition
;

Group:
'GROUP' name=ID
elements += (GroupElement)+
'END_GROUP'
;

GroupElement:
Entity|TemplateReference|TemplateDefinition|ConditionalStatement
;

Entity:
'ENTITY' name=ID 
value = Value
'END_ENTITY'
;

TemplateDefinition:
'define' 'template' name = ID '[' templatevariable=TemplateVariable ']'
elements += (Entity|TemplateReference)+
'end_define'
;

TemplateVariable:
name=ID
;

TemplateReference:
{TemplateReference}
'reference' name=ID 'to' reference=[TemplateDefinition|ID] '[' elements=IntElementList ']'
;

Value:
	'value' value=INT
;

IntElementList:
	firstelement = INT
	(','elements+=INT)*
;

ConditionalStatement:
	'if' '(' expression=Expression ')'
	'{'
	then+=Entity+
	'}'
;

Expression:
	reference = [ReferencableElements|QUALIFIEDNAME]
;

ReferencableElements:
	Entity | TemplateReference
;

terminal ID:
	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;

terminal QUALIFIEDNAME:
	ID ('.'ID)*
;



and here an example code:

HIERARCHY 

GROUP group
	define template Template[Index]
		ENTITY tempentity
			value 1
		END_ENTITY
	end_define
	
	reference Reference1 to Template[1,3]
 
  if (group.Reference1)
  {
	ENTITY entity
		value 1
	END_ENTITY
  }
END_GROUP

END_HIERARCHY


My problem here is that i can just make a reference to "group.Reference1", but I want to make a reference to "group.Reference1.tempentity".
Re: Cross reference to a cross reference ?? [message #1063778 is a reply to message #1063776] Fri, 14 June 2013 04:09 Go to previous messageGo to next message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
After the "generate fORUM" the link "http: // www. xtext. org/ example/ forum/ FORUM" is missing because I wasn't allowed to write in my post.
Sorry for that
Re: Cross reference to a cross reference ?? [message #1063782 is a reply to message #1063778] Fri, 14 June 2013 04:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6131
Registered: July 2009
Senior Member
So you want to so aomething like

http://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-expressions/
Re: Cross reference to a cross reference ?? [message #1064207 is a reply to message #1063782] Tue, 18 June 2013 05:08 Go to previous message
Sascha Gstir is currently offline Sascha Gstir
Messages: 12
Registered: May 2013
Junior Member
yeeeeah! It works! Awesome! Thank you very much Christian!

I have implemented it now into my model and it works very well, but I got another conflict.
I am not allowed to use the dots, because I am also using normal references in the expressions of the
conditional statements. So I mean reference to elements which are not defined in templates.
For that I use just the following terminal rule:

terminal QUALIFIEDNAME:	ID ('.'ID)*; 


and I use this one in my references which look like that:

Reference returns Expression:
	{Reference}
	reference = [ConfkeyOrOption|QUALIFIEDNAME] 
;


And because both of them are defined with dots as separator the parser seems to have a problem with that.

Do you have another advice for me how I can solve that conflict?
Because I want to write both references with dots as separartor.
Previous Topic:Use Xtext in Runtime
Next Topic:GeneratorRegistry unleashed :-) (delete pls)
Goto Forum:
  


Current Time: Sat Jul 26 07:25:23 EDT 2014

Powered by FUDForum. Page generated in 0.27114 seconds