Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » DSL with "private" sections
DSL with "private" sections [message #779857] Mon, 16 January 2012 17:29 Go to next message
Klaus Birken is currently offline Klaus BirkenFriend
Messages: 25
Registered: December 2009
Junior Member
Hi all,

I am building a DSL where some objects must be hidden from outside a given scope. I.e., it should support something like "private" sections in C++ or private members in Java.

Simplified "toy" Smile example (left out import-stuff):
Model:
  (boxes+=Box)*
  (toys+=Toy)*
  (kids+=Kid)* ;

Box: 'box' name=ID (toys+=Toy)*;

Toy: 'toy' name=ID; 

Kid: name=ID 'has' toy=[Toy|ID];


A kid should be able to reference only the toys which are part of Model.toys, not those which are in a box (Box.toys). In an extended version, each kid might have some access to more toys depending on the boxes' names.


After reading some documentation, I guess I have to provide my own implementation of IResourceDescription.Manager to avoid the "private" EObjects being published in the index. Additionally, I would have to add an additional filter (using local scoping) for handling intra-file references correctly.

However, this solution seems quite clumsy, there might be something more elegant. And: The above solution starts getting complicated in conjunction with FQN - how/where should the name computation for the exported EObjectDescription objects be done? So, I guess I went down the wrong path.

Did someone implement such "private"ish stuff before?

Thanks in advance and regards,
Klaus
Re: DSL with "private" sections [message #779892 is a reply to message #779857] Mon, 16 January 2012 18:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this basically works out of the box (with proper use of qualified names)
(in your case give model a name)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DSL with "private" sections [message #779905 is a reply to message #779892] Mon, 16 January 2012 19:40 Go to previous messageGo to next message
Klaus Birken is currently offline Klaus BirkenFriend
Messages: 25
Registered: December 2009
Junior Member
Hi Christian,

even after giving Model a name, it seems to me that the default behaviour with namespaces is that members of Box.toys can still be referenced. Where would the filtering be done which hides Box.toys members but keeps Model.toys members visible (note that Box.toys is just another Toy rule call, not a reference)?

Regards,
Klaus
Re: DSL with "private" sections [message #779921 is a reply to message #779905] Mon, 16 January 2012 20:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i guess it is time for you to read something about scoping (google is your friend). there are lots of possibilities to solve such a problem.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DSL with "private" sections [message #780094 is a reply to message #779857] Tue, 17 January 2012 07:02 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Klaus,

I'd allow to establish the cross reference but validate the visibility
explicitly. The error messages will be more helpful. You may want to
compare that approach with JDTs error messages if you try access
invisible members of a class.

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

Am 16.01.12 18:29, schrieb Klaus Birken:
> Hi all,
>
> I am building a DSL where some objects must be hidden from outside a
> given scope. I.e., it should support something like "private" sections
> in C++ or private members in Java.
> Simplified "toy" :) example (left out import-stuff):
>
> Model:
> (boxes+=Box)*
> (toys+=Toy)*
> (kids+=Kid)* ;
>
> Box: 'box' name=ID (toys+=Toy)*;
>
> Toy: 'toy' name=ID;
> Kid: name=ID 'has' toy=[Toy|ID];
>
>
> A kid should be able to reference only the toys which are part of
> Model.toys, not those which are in a box (Box.toys). In an extended
> version, each kid might have some access to more toys depending on the
> boxes' names.
>
>
> After reading some documentation, I guess I have to provide my own
> implementation of IResourceDescription.Manager to avoid the "private"
> EObjects being published in the index. Additionally, I would have to add
> an additional filter (using local scoping) for handling intra-file
> references correctly.
>
> However, this solution seems quite clumsy, there might be something more
> elegant. And: The above solution starts getting complicated in
> conjunction with FQN - how/where should the name computation for the
> exported EObjectDescription objects be done? So, I guess I went down the
> wrong path.
>
> Did someone implement such "private"ish stuff before?
>
> Thanks in advance and regards,
> Klaus
>
Re: DSL with "private" sections [message #780113 is a reply to message #780094] Tue, 17 January 2012 07:52 Go to previous message
Klaus Birken is currently offline Klaus BirkenFriend
Messages: 25
Registered: December 2009
Junior Member
Thanks Sebastian, this was a good hint - the implementation is quite easy this way and it will help the user of the DSL to understand the visibility rules.

Regards,
Klaus

Previous Topic:cursor position in autocompletion using tabs
Next Topic:Simple Grammar causes Infinite Loop.
Goto Forum:
  


Current Time: Fri Apr 26 12:08:29 GMT 2024

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

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

Back to the top