Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping: merge elements in logical groups
Scoping: merge elements in logical groups [message #629044] Sun, 26 September 2010 18:32 Go to next message
awidegreen  is currently offline awidegreen Friend
Messages: 14
Registered: July 2010
Junior Member
Hej everyone,

I want to implement a construct that is able to distinguish between different logical groups (see example below).

Therefore I defined the following grammar:
grammar org.test.ExtScope with org.eclipse.xtext.common.Terminals

generate extScope "http://www.test.org/ExtScope"

Model:
	(elements+=Element)+;

Element:	
	'element' name=QualifiedName '{'
		'desc' '=' string=STRING
		(functions+=AbstractFunction)*	
	'}';

AbstractFunction:
	RequestFunction | ResponseFunction;
	
RequestFunction:
	'request' name=QualifiedName 'desc' '=' desc=STRING;

ResponseFunction:
	'response' name=QualifiedName 'desc' '=' desc=STRING;
	
QualifiedName:
  ID ('.' ID)*;


As you can see, the name of the "response" and "request" functions are in the same scope (of element a). So the following example do NOT work.

element a {
	desc = "general desc"
	request myFunc desc = "myDescForReq"
	response myFunc desc = "myDescForRes"
        // more requests and responses
}

Generally, I want to reference request respectively response functions with QualifiedName like: a.responses.myFunc and a.requests.myFunc, to distinguish that the one is a request and the other one a response.

Is there an appropriate solution for that functionality? Do I have to define my own ScopeProvider? Or maybe I only have to adjust my grammar-definition....? Please keep in mind that this is only an example grammar, the actual grammar is much bigger.

tack,
a
Re: Scoping: merge elements in logical groups [message #629048 is a reply to message #629044] Sun, 26 September 2010 19:33 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I think it should suffice to implement a name provider that adds the "missing" name elements.

Alex
Re: Scoping: merge elements in logical groups [message #629049 is a reply to message #629044] Sun, 26 September 2010 19:34 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi A,

what do you mean - it does not work? I don't see any cross references in
your example so the code should not depend on scopes. If you are
refering to validation problems for duplicate names, please bind your
own implementation of NamesAreUniqueValidationHelper.getClusterTypes()
according to its JavaDoc.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 26.09.10 20:32, schrieb awidegreen:
> Hej everyone,
>
> I want to implement a construct that is able to distinguish between
> different logical groups (see example below).
> Therefore I defined the following grammar:
>
> grammar org.test.ExtScope with org.eclipse.xtext.common.Terminals
>
> generate extScope "http://www.test.org/ExtScope"
>
> Model:
> (elements+=Element)+;
>
> Element:
> 'element' name=QualifiedName '{'
> 'desc' '=' string=STRING
> (functions+=AbstractFunction)*
> '}';
>
> AbstractFunction:
> RequestFunction | ResponseFunction;
>
> RequestFunction:
> 'request' name=QualifiedName 'desc' '=' desc=STRING;
>
> ResponseFunction:
> 'response' name=QualifiedName 'desc' '=' desc=STRING;
>
> QualifiedName:
> ID ('.' ID)*;
>
>
> As you can see, the name of the "response" and "request" functions are
> in the same scope (of element a). So the following example do NOT work.
>
> element a {
> desc = "general desc"
> request myFunc desc = "myDescForReq"
> response myFunc desc = "myDescForRes"
> // more requests and responses
> }
>
> Generally, I want to reference request respectively response functions
> with QualifiedName like: a.responses.myFunc and a.requests.myFunc, to
> distinguish that the one is a request and the other one a response.
>
> Is there an appropriate solution for that functionality? Do I have to
> define my own ScopeProvider? Or maybe I only have to adjust my
> grammar-definition....? Please keep in mind that this is only an example
> grammar, the actual grammar is much bigger.
> tack,
> a
>
Re: Scoping: merge elements in logical groups [message #629050 is a reply to message #629049] Sun, 26 September 2010 19:41 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Sorry - I think I missed the point :-)

Am 26.09.10 21:34, schrieb Sebastian Zarnekow:
> Hi A,
>
> what do you mean - it does not work? I don't see any cross references in
> your example so the code should not depend on scopes. If you are
> refering to validation problems for duplicate names, please bind your
> own implementation of NamesAreUniqueValidationHelper.getClusterTypes()
> according to its JavaDoc.
>
> Regards,
> Sebastian
Re: Scoping: merge elements in logical groups [message #631613 is a reply to message #629048] Fri, 08 October 2010 08:21 Go to previous messageGo to next message
awidegreen  is currently offline awidegreen Friend
Messages: 14
Registered: July 2010
Junior Member
Hej,

Alexander Nittka wrote on Sun, 26 September 2010 15:33

I think it should suffice to implement a name provider that adds the "missing" name elements.



Okay, that's what I did ...
public class MyDeclarativeQualifiedNameProvider extends
		DefaultDeclarativeQualifiedNameProvider {

	public String qualifiedName(AbstractFunction func) {
		StringBuilder sb = new StringBuilder();
		
		sb.append(((Element)func.eContainer()).getName());
		sb.append(".");
		
		if (func instanceof RequestFunction) {
			sb.append("requests");
		} else if (func instanceof ResponseFunction) {
			sb.append("responses");
		}
		
		sb.append(".");
		sb.append(func.getName());
		
		System.out.println("The qName is: " + sb.toString());
		
		return sb.toString();
	}
}


But, am I right, that I'm going to lose the default fqn-feature which is normally provided by the DefaultDecQNameProvider? So, do I have to implement the qualifiedName-methods for every 'nameable' subclass of my generate metamodell? Maybe there is a way to combine both?

tack,
a
Re: Scoping: merge elements in logical groups [message #631652 is a reply to message #631613] Fri, 08 October 2010 11:38 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

no. Your method changes the default implementation only for elements of type AbstractFunction (and names built using names of AbstractFuntion elements).

Alex
Re: Scoping: merge elements in logical groups [message #631661 is a reply to message #631652] Fri, 08 October 2010 12:08 Go to previous message
awidegreen  is currently offline awidegreen Friend
Messages: 14
Registered: July 2010
Junior Member
Quote:
no. Your method changes the default implementation only for elements of type AbstractFunction (and names built using names of AbstractFuntion elements).


thanks ... i was just writing an answer where I wanted to mention that - as I read on s.efftinges blog. ;)

tack,
a

[Updated on: Fri, 08 October 2010 12:14]

Report message to a moderator

Previous Topic:manipulate textual model
Next Topic:Xtext Index
Goto Forum:
  


Current Time: Fri Apr 26 07:19:38 GMT 2024

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

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

Back to the top