Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Showing and hiding grammar feature in textual representation
Showing and hiding grammar feature in textual representation [message #991343] Tue, 18 December 2012 15:27 Go to next message
Marco Naddeo is currently offline Marco NaddeoFriend
Messages: 62
Registered: November 2012
Member
Hi.

I have to show or hide a feature of an element defined in my language grammar, in the textual representation editable by the programmer in the editor. The idea is that of "compressing" part of the code upon request.

I think that the serializer could help me because this grammar feature has, anyway, to be stored into the EMF model and then serialized or not according to the preferences of the user. I read about transient values in the documentation, which can be serialized or not using appropriate transient value services.

But when apply the serialization? Maybe I can serialize the "long" version of code, obtaining the "short" in another file, but then how can I allow the user to work on the "short" version, storing that (hidden) feature in the EMF model in some other manner (not writing it explicitly)? In such a way to be able to restore later the updated "long" version, when needed?

Basically, I should have two different textual representations (one "short" and one "long") of the same EMF model, which are held constantly and mutually aligned.

I am very confused, could you please help me? Sad

[Updated on: Tue, 18 December 2012 15:27]

Report message to a moderator

Re: Showing and hiding grammar feature in textual representation [message #991353 is a reply to message #991343] Tue, 18 December 2012 16:46 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Seems unnecessary complex.

As a suggestion; support both the long and the short form in the same
grammar and use a boolean that is stored in the model to indicate which
form to use. In the UI, give the user an action that switches between
the two forms (i.e. perform a semantic change that will trigger the
serializer). Unfortunately you will loose formatting and any comments
inside the modified section (unless you write your own comment
reconciler to try to assign the comments and regenerate them).

If you have trouble with supporting both forms at the same time in the
grammar because of ambiguities it gets much more complex.

If this is a short or long form of the entire language, then you are
perhaps better of with two separate grammars - both using the same
metamodel. These files would have different suffixes .mydsll, and
..mydssls (for long and short version - or somesuch).

If you want to transform between then; load one, then remove the text
from the resource, then save resource as the other. Unfortunately you
will loose all formatting and comments (everything that is hidden) in
such a process and if you want to keep comments etc. you need to write a
reconciler that associates comments with model elements and then outputs
them when serializing. Not an easy task. (I do similar things in
cloudsmith / geppetto @ github).

Lastly, depending on the reasons why things should be compressed; there
is the concept of "folding", and maybe the short form only exists to
show an abbreviated versions of more complex logic; maybe it is possible
to tweak the folding to show a custom result when a section is folded.

Hope that helps.
- henrik

On 2012-18-12 16:27, Marco Naddeo wrote:
> Hi.
>
> I have to show or hide a feature of an element defined in my language
> grammar, in the textual representation editable by the programmer in the
> editor. The idea is that of "compressing" part of the code upon request.
>
> I think that the serializer could help me because this grammar feature
> has, anyway, to be stored into the EMF model and then serialized or not
> according to the preferences of the user. I read about transient values
> in the documentation, which can be serialized or not using appropriate
> transient value services.
>
> But when apply the serialization? Maybe I can serialize the "long"
> version of code, obtaining the "short" in another file, but then how can
> I allow the user to work on the "short" version, storing that (hidden)
> feature in the EMF model in some other manner (not writing it
> explicitly)? In such a way to be able to restore later the updated
> "long" version, when needed?
>
> Basically, I should have two different textual representations (one
> "short" and one "long") of the same EMF model, which are held constantly
> and mutually aligned.
>
> I am very confused, could you please help me? :(
Previous Topic:Parameterized parser rule
Next Topic:[M4 Release] The new type system
Goto Forum:
  


Current Time: Fri Apr 19 21:16:49 GMT 2024

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

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

Back to the top