Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Association and cross-referencing
Association and cross-referencing [message #1781463] Wed, 07 February 2018 09:23 Go to next message
Eclipse UserFriend
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 03:42 Go to previous messageGo to next message
Eclipse UserFriend
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 04:52 Go to previous messageGo to next message
Eclipse UserFriend
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 03:06 Go to previous message
Eclipse UserFriend
As Christian said, you have to implement scoping, such that the candidates of the second cross reference depend on the linking of the first.
Previous Topic:Build xtext with maven
Next Topic:Creating new xtext resource in quickfix
Goto Forum:
  


Current Time: Tue Jul 22 18:12:39 EDT 2025

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

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

Back to the top