Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Association and cross-referencing
Association and cross-referencing [message #1781463] Wed, 07 February 2018 14:23 Go to next message
Philipp Schneider is currently offline Philipp SchneiderFriend
Messages: 2
Registered: February 2018
Location: München
Junior Member
Hey,

I am trying ways to link and access contained items with cross-referenced IDs, here, I have the following grammar:

Domainmodel:
	'dmodel' name=ID
	"{"
		('cmpTypes' '{' ctps+=CMPType	( "," ctps+=CMPType)* '}' )? 
	   	('set' '{'
	   		(cmps+=CMP ("," cmps+=CMP)*)?
	   		(prt=[PRT | QualifiedName])?
	   	'}'
	   	)?
	'}'
	;
CMPType: 
	'type' name=ID	'{' ('prts' '(' prts+=PRT ( "," prts+=PRT)* ')' )? '}'
	;
CMP:
	'cmp'	name=QualifiedName 'as' cmpType=[CMPType|QualifiedName]
	;
PRT:
	name=ID
	;
QualifiedName:
    ID ('.' ID)*
    ;


and here is how the DSL should look like:

dmodel D1 {
  cmpTypes { 
	type C1 { 
		prts (P1, P2)
	},
	type C2 {  
		prts (P3, P4)
		}
	}
  set { 
	cmp x as C1,
	cmp y as C1,
        cmp z as C2

        //access items in 'prts' (P1, P2, ...) by  cmp IDs (x, y, z)
	x.P1 // rather than C1.P1 which works 
	y.P3
	}		
}


I want to associate cmp IDs (x, y, z) with items in cmpTypes (C1, C2 ...) and then access contained items in 'prts' (P1, P2, ...) by cmp IDs (x, y, z).
Any suggestions or examples how I could realize this?


Re: Association and cross-referencing [message #1781526 is a reply to message #1781463] Thu, 08 February 2018 08:42 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Actually you want to refer to a CMP ('x') first and from there to a PRT. If I understand this correct 'x.P1' is a name which is in its first part a cross reference to CMP, followed by a reference to a PRT. So you'll need a rule like 'PRTRef':

PRTRef: cmp=[CMP|ID] '.' prt=[PRT|ID];

I used ID here instead of QualifiedName since the '.' would become ambiguous.

Then you'll have to implement scoping for reference PRTRef_prt in the IScopeProvider.
Re: Association and cross-referencing [message #1781537 is a reply to message #1781526] Thu, 08 February 2018 09:52 Go to previous messageGo to next message
Philipp Schneider is currently offline Philipp SchneiderFriend
Messages: 2
Registered: February 2018
Location: München
Junior Member
Thank you for the reply, but just realized this way it will require me extra work to validate the reference. After the dot, referenced 'PRT' must be only the 'PRT' where it's containing CMPType is set to 'CMP'.

As in the example, it shouldn't allow references like z.P1 rather z.P3 or z.P4, the y.P3 must be an error too. Any suggestions?
Re: Association and cross-referencing [message #1781684 is a reply to message #1781537] Mon, 12 February 2018 08:06 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
As Christian said, you have to implement scoping, such that the candidates of the second cross reference depend on the linking of the first.

---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Build xtext with maven
Next Topic:Creating new xtext resource in quickfix
Goto Forum:
  


Current Time: Thu Apr 25 20:45:58 GMT 2024

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

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

Back to the top