Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restrict the presence of specific elements in Scope of others
Restrict the presence of specific elements in Scope of others [message #671898] Thu, 19 May 2011 09:52 Go to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

I have a language enabling to declare something like that:
class A[T] {
  attribute x: T
}


Would be something like that in xtext
ClassDecl: "class" name=ID ("[" typeParams+=TypeParamDecl ("," typeParams+=TypeParamDecl)* "]")? "{"
  attrs+=AttributeDecl*
"}";
AttributeDecl: "attribute" name=ID ":" type=[TypeParamDecl];
TypeParamDecl: name=ID;

I have a problem because the generated editors accept to write:
class B {
  attribute y: A.T
}

which I don't want.

Any idea on how to restrict the places where T is visible? I am using the exporting.QualifiedNamesFragment.
Re: Restrict the presence of specific elements in Scope of others [message #671900 is a reply to message #671898] Thu, 19 May 2011 10:01 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I assume class A[T] is to mean that only T is visible within Class A. The simplest solution would be to restrict the scope for type in AttributeDecl making only the typeParams of the containing ClassDecl visible.
The pseudocode is something like return Scopes.scopeFor(((ClassDecl)attributeDeclaration.eContainer()).getTypeParams());

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: Restrict the presence of specific elements in Scope of others [message #671963 is a reply to message #671898] Thu, 19 May 2011 13:24 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Victor,

please refer to the section on scoping in the docs. You'll have to
implement these rules in your YourLangScopeProvider.

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


Am 19.05.11 11:52, schrieb Victor:
> Hi,
>
> I have a language enabling to declare something like that:
>
> class A[T] {
> attribute x: T
> }
>
>
> Would be something like that in xtext
>
> ClassDecl: "class" name=ID ("[" typeParams+=TypeParamDecl (","
> typeParams+=TypeParamDecl)* "]")? "{"
> attrs+=AttributeDecl*
> "}";
> AttributeDecl: "attribute" name=ID ":" type=[TypeParamDecl];
> TypeParamDecl: name=ID;
>
> I have a problem because the generated editors accept to write:
>
> class B {
> attribute y: A.T
> }
>
> which I don't want.
>
> Any idea on how to restrict the places where T is visible? I am using
> the exporting.QualifiedNamesFragment.
Previous Topic:Handling extreme parser decisions
Next Topic:Run command
Goto Forum:
  


Current Time: Fri Apr 26 11:21:51 GMT 2024

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

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

Back to the top