Skip to main content



      Home
Home » Modeling » TMF (Xtext) » DSL with "private" sections
DSL with "private" sections [message #779857] Mon, 16 January 2012 12:29 Go to next message
Eclipse UserFriend
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 13:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: DSL with "private" sections [message #779905 is a reply to message #779892] Mon, 16 January 2012 14:40 Go to previous messageGo to next message
Eclipse UserFriend
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 15:28 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: DSL with "private" sections [message #780094 is a reply to message #779857] Tue, 17 January 2012 02:02 Go to previous messageGo to next message
Eclipse UserFriend
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 02:52 Go to previous message
Eclipse UserFriend
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: Sun Jul 13 15:05:10 EDT 2025

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

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

Back to the top