Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross Linking Complex Types  () 1 Vote
Cross Linking Complex Types [message #825832] Wed, 21 March 2012 10:09 Go to next message
Malinda Kapuruge is currently offline Malinda KapurugeFriend
Messages: 2
Registered: March 2012
Junior Member
Hi,
I have an issue cross linking in my grammar given below. I searched the forum but unable to locate an exact solution.

Explanation:

Consider the following grammar[1]. In brief, Suppose I need to write multiple groups each consist of multiple students. Students are always declared inside a group. A registry contains references to these students. A reference looks like groupId.studentId. e.g., grp1.std1 in the example given in [2].

The Problem: How to correctly refer to 'A Student in a Group' ?

Cheers,
Malinda


[1]

-----------Grammar Start----------
Script: 
	(registries+=Registry)*
	(groups+=Group)* 
;

Registry:
	'Registry' name=ID '{' (ref+=Reference)* '}'
	;

Reference :
	groupId=[Group]'.'studentId=[Student] ';'
;
Group:
	'Group' name=ID '{'		(students+=Student)*	'}';
	
Student:
	'Student' name=ID ';'
;

-----------Grammar End----------

[2]
-----------Script Start----------
Registry r1 {	
	grp1.std1; //Problem here in s1. Error: Couldn't resolve reference to Student s1
}

Group grp1 {
	Student std1 ;
}

Group grp2{
	Student std2 ;
	Student std3 ;
}

-----------Script End----------
Re: Cross Linking Complex Types [message #825838 is a reply to message #825832] Wed, 21 March 2012 10:17 Go to previous messageGo to next message
Holger Schill is currently offline Holger SchillFriend
Messages: 75
Registered: July 2009
Member
Hi Malinda,

the normal way is to deal with qualifiedNames. So the Registry Rule should look like this:

Registry:
'Registry' name=ID '{' (ref+=[Student|QualifiedName])* '}'
;

QualifiedName:
ID ('.' ID)*;

The default QualifiedNameprovider will scope a Student with the name of the group followed by a point and then the name of the student. A DataTypeRule named QualifiedName enables you to crossreferenz such names.

Cheers,
Holger



--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Cross Linking Complex Types [message #826305 is a reply to message #825838] Wed, 21 March 2012 23:05 Go to previous messageGo to next message
Malinda Kapuruge is currently offline Malinda KapurugeFriend
Messages: 2
Registered: March 2012
Junior Member
Hi Holger,
This solved the problem in the editor. Thanks very much.
But then this created another problem as well. Earlier I used to generate an XML based on the Script via XTend. For that I need to separate a reference (registry entry) into two parts, i.e., group id + student id. With this I have only ONE value assigned to variable 'ref'. Rather than performing string manipulations at the Xtend, is it possible to assign the group id and the student id parts in the reference to two variables?
I tried to do something as this but it cannot be possibly done as variable y is in a loop.

QualifiedName:
x=ID ('.' y=ID)*;
In general my question is How to access the individual parts of a qualified name?
Cheers,
Malinda
Re: Cross Linking Complex Types [message #869470 is a reply to message #826305] Thu, 03 May 2012 12:51 Go to previous message
Holger Schill is currently offline Holger SchillFriend
Messages: 75
Registered: July 2009
Member
There are several solutions for that problem.

1. Ask the eContainer of a Student for its name. Voila the groups name.

2. Let the grammar as it was and create a custom scoping method for scope_Reference_Studentid(Reference ref,EReference x)
Where you could ask for the group and just make the students that are contained visible.

public IScope scope_Reference_Studentid(Reference ref,EReference x){
return Scopes.scopeFor(x.getGroupId().getSudents());
}

Cheers,
Holger


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Global Scoping with ImportUriGlobalScopeProvider
Next Topic:Where did org.eclipse.xtext.util.formallang.IGrammarFactory disappear to from xtext 2.0.0 to 2.1.1?
Goto Forum:
  


Current Time: Wed Apr 24 18:21:05 GMT 2024

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

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

Back to the top