Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializing invalid content?
Serializing invalid content? [message #753594] Thu, 27 October 2011 22:07 Go to next message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
Hi,

We currently have a working Xtext editor for our DSL and are in the process
of creating a graphical editor to allow for editing of the same Xtext
resource. We are hoping to use the Xtext Serializer to write out the model
as text when the user saves the content of the graphical editor. However,
the model may not always be valid when the save command is invoked, but we
would still want to save the current state of the model (e.g. user needs to
close the editor but is not able to finish creating a valid model). After
reading questions/answers posted to this forum, my understanding is that the
Xtext Serializer will not be able to serialize an invalid/incomplete model,
is that correct? If so, what are my options in this case? Is writing my own
custom serializer the only option?

Mary
Re: Serializing invalid content? [message #753601 is a reply to message #753594] Fri, 28 October 2011 01:08 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
How about saving it as xml? Just give it a different extension.
Some information is lost though if the user starts with text (containing
comments and formatting) and then "trashes" the model.

You could also save the edits as transformations, and only serialize to
text when it is possible.

Or, make grammar more forgiving - move more to validation.

- henrik

On 10/28/11 12:07 AM, Mary Komor wrote:
> Hi,
>
> We currently have a working Xtext editor for our DSL and are in the
> process of creating a graphical editor to allow for editing of the same
> Xtext resource. We are hoping to use the Xtext Serializer to write out
> the model as text when the user saves the content of the graphical
> editor. However, the model may not always be valid when the save command
> is invoked, but we would still want to save the current state of the
> model (e.g. user needs to close the editor but is not able to finish
> creating a valid model). After reading questions/answers posted to this
> forum, my understanding is that the Xtext Serializer will not be able to
> serialize an invalid/incomplete model, is that correct? If so, what are
> my options in this case? Is writing my own custom serializer the only
> option?
>
> Mary
Re: Serializing invalid content? [message #753610 is a reply to message #753594] Fri, 28 October 2011 04:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Mary

Vote for or contribute a solution to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340409.

With the new serializer structure, I suspect that it's not that difficult.

But even without fixing the enhancement request, you could encapsulate
the bad input regions as distinctive comments on dummy valid input and
use the comment serialization discussed in the "Comment serialization"
thread "news://news.eclipse.org:119/j7s40a$s6b$1@news.eclipse.org.

Regards

Ed Willink

On 27/10/2011 23:07, Mary Komor wrote:
> Hi,
>
> We currently have a working Xtext editor for our DSL and are in the
> process of creating a graphical editor to allow for editing of the
> same Xtext resource. We are hoping to use the Xtext Serializer to
> write out the model as text when the user saves the content of the
> graphical editor. However, the model may not always be valid when the
> save command is invoked, but we would still want to save the current
> state of the model (e.g. user needs to close the editor but is not
> able to finish creating a valid model). After reading
> questions/answers posted to this forum, my understanding is that the
> Xtext Serializer will not be able to serialize an invalid/incomplete
> model, is that correct? If so, what are my options in this case? Is
> writing my own custom serializer the only option?
>
> Mary
Re: Serializing invalid content? [message #753614 is a reply to message #753601] Fri, 28 October 2011 04:52 Go to previous messageGo to next message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
Hi Henrik,

Thanks for the suggestions!

Saving as XML is not an option as we also want our users to be able to edit
the same file in the text format in other text editor... primarily in our
Xtext-based editor.

Ideally, we want to serialize whenever the save command is invoked... so
that if the same file is also opened in the Xtext-based text editor, the
model will be refreshed and the same content will be seen in both editors.

I am going to explore the option of making the grammar more forgiving.
Although, I do wonder what existing feature/functionality may suffer because
of that? With respect with validation, we can certainly beef up validation
or defer more to the compiler.

Mary

"Henrik Lindberg" <henrik.lindberg@cloudsmith.com> wrote in message
news:j8cujr$i22$1@news.eclipse.org...
> How about saving it as xml? Just give it a different extension.
> Some information is lost though if the user starts with text (containing
> comments and formatting) and then "trashes" the model.
>
> You could also save the edits as transformations, and only serialize to
> text when it is possible.
>
> Or, make grammar more forgiving - move more to validation.
>
> - henrik
>
> On 10/28/11 12:07 AM, Mary Komor wrote:
>> Hi,
>>
>> We currently have a working Xtext editor for our DSL and are in the
>> process of creating a graphical editor to allow for editing of the same
>> Xtext resource. We are hoping to use the Xtext Serializer to write out
>> the model as text when the user saves the content of the graphical
>> editor. However, the model may not always be valid when the save command
>> is invoked, but we would still want to save the current state of the
>> model (e.g. user needs to close the editor but is not able to finish
>> creating a valid model). After reading questions/answers posted to this
>> forum, my understanding is that the Xtext Serializer will not be able to
>> serialize an invalid/incomplete model, is that correct? If so, what are
>> my options in this case? Is writing my own custom serializer the only
>> option?
>>
>> Mary
>
Re: Serializing invalid content? [message #753620 is a reply to message #753610] Fri, 28 October 2011 05:45 Go to previous messageGo to next message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
Hi Ed,

I could not "vote" for the enhancement 340409, but have added a comment
indicating my interest for a solution.

I've read the "Comment serialization" thread and understand the creative
solution you implemented. For my case, I am not sure what I would need to
extend/override in order to detect/handle the problematic/invalid regions
that cannot be serialized.

Mary

"Ed Willink" <ed@willink.me.uk> wrote in message
news:j8daqr$9cd$1@news.eclipse.org...
> Hi Mary
>
> Vote for or contribute a solution to
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=340409.
>
> With the new serializer structure, I suspect that it's not that difficult.
>
> But even without fixing the enhancement request, you could encapsulate the
> bad input regions as distinctive comments on dummy valid input and use the
> comment serialization discussed in the "Comment serialization" thread
> "news://news.eclipse.org:119/j7s40a$s6b$1@news.eclipse.org.
>
> Regards
>
> Ed Willink
>
> On 27/10/2011 23:07, Mary Komor wrote:
>> Hi,
>>
>> We currently have a working Xtext editor for our DSL and are in the
>> process of creating a graphical editor to allow for editing of the same
>> Xtext resource. We are hoping to use the Xtext Serializer to write out
>> the model as text when the user saves the content of the graphical
>> editor. However, the model may not always be valid when the save command
>> is invoked, but we would still want to save the current state of the
>> model (e.g. user needs to close the editor but is not able to finish
>> creating a valid model). After reading questions/answers posted to this
>> forum, my understanding is that the Xtext Serializer will not be able to
>> serialize an invalid/incomplete model, is that correct? If so, what are
>> my options in this case? Is writing my own custom serializer the only
>> option?
>>
>> Mary
>
Re: Serializing invalid content? [message #753650 is a reply to message #753620] Fri, 28 October 2011 08:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Mary,

Perhaps you ought to preprocess an incomplete model to make is
sufficiently complete such that the serializer would be happy. E.g., if
a name is necessary, you could set a placeholder name. In fact your
editor should probably try to be creating as complete a model as
possible, at least complete enough that it can be sensibly serialized.
After all, if you want to be able to read it again, the parser will have
to recognize it, so one way or the other, you will have to supply
default values for things that are required by the grammar.


On 28/10/2011 7:45 AM, Mary Komor wrote:
> Hi Ed,
>
> I could not "vote" for the enhancement 340409, but have added a
> comment indicating my interest for a solution.
>
> I've read the "Comment serialization" thread and understand the
> creative solution you implemented. For my case, I am not sure what I
> would need to extend/override in order to detect/handle the
> problematic/invalid regions that cannot be serialized.
>
> Mary
>
> "Ed Willink" <ed@willink.me.uk> wrote in message
> news:j8daqr$9cd$1@news.eclipse.org...
>> Hi Mary
>>
>> Vote for or contribute a solution to
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=340409.
>>
>> With the new serializer structure, I suspect that it's not that
>> difficult.
>>
>> But even without fixing the enhancement request, you could
>> encapsulate the bad input regions as distinctive comments on dummy
>> valid input and use the comment serialization discussed in the
>> "Comment serialization" thread
>> "news://news.eclipse.org:119/j7s40a$s6b$1@news.eclipse.org.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 27/10/2011 23:07, Mary Komor wrote:
>>> Hi,
>>>
>>> We currently have a working Xtext editor for our DSL and are in the
>>> process of creating a graphical editor to allow for editing of the
>>> same Xtext resource. We are hoping to use the Xtext Serializer to
>>> write out the model as text when the user saves the content of the
>>> graphical editor. However, the model may not always be valid when
>>> the save command is invoked, but we would still want to save the
>>> current state of the model (e.g. user needs to close the editor but
>>> is not able to finish creating a valid model). After reading
>>> questions/answers posted to this forum, my understanding is that the
>>> Xtext Serializer will not be able to serialize an invalid/incomplete
>>> model, is that correct? If so, what are my options in this case? Is
>>> writing my own custom serializer the only option?
>>>
>>> Mary
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Serializing invalid content? [message #753682 is a reply to message #753614] Fri, 28 October 2011 10:36 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 10/28/11 6:52 AM, Mary Komor wrote:
> Hi Henrik,
>
> Thanks for the suggestions!
>
> Saving as XML is not an option as we also want our users to be able to
> edit the same file in the text format in other text editor... primarily
> in our Xtext-based editor.
>
The idea was to save as XML as a sort of "persist editor state" - a
reconciliation would be needed at some future point.

Ed's suggestions would be the best way IMO - don't let the user create
something that is broken.

- henrik
Re: Serializing invalid content? [message #753759 is a reply to message #753682] Fri, 28 October 2011 15:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think you actually need both levels of fixes.

When creating, you should provide wrappers for invalid content so that
the user can save.

When loading, you should provide wrappers for invalid content so that
the user can load. (A new editor version/meta-model version/tooling
enhancement may make a previously 'correct' model invalid.)

Regards

Ed Willink

On 28/10/2011 11:36, Henrik Lindberg wrote:
> On 10/28/11 6:52 AM, Mary Komor wrote:
>> Hi Henrik,
>>
>> Thanks for the suggestions!
>>
>> Saving as XML is not an option as we also want our users to be able to
>> edit the same file in the text format in other text editor... primarily
>> in our Xtext-based editor.
>>
> The idea was to save as XML as a sort of "persist editor state" - a
> reconciliation would be needed at some future point.
>
> Ed's suggestions would be the best way IMO - don't let the user create
> something that is broken.
>
> - henrik
Re: Serializing invalid content? [message #754468 is a reply to message #753650] Wed, 02 November 2011 16:00 Go to previous messageGo to next message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
Ed, thanks for your suggestion. Pre-processing is definitely an option I
will explore.

Mary

"Ed Merks" <ed.merks@gmail.com> wrote in message
news:j8dn3s$18u$2@news.eclipse.org...
> Mary,
>
> Perhaps you ought to preprocess an incomplete model to make is
> sufficiently complete such that the serializer would be happy. E.g., if a
> name is necessary, you could set a placeholder name. In fact your editor
> should probably try to be creating as complete a model as possible, at
> least complete enough that it can be sensibly serialized. After all, if
> you want to be able to read it again, the parser will have to recognize
> it, so one way or the other, you will have to supply default values for
> things that are required by the grammar.
>
>
> On 28/10/2011 7:45 AM, Mary Komor wrote:
>> Hi Ed,
>>
>> I could not "vote" for the enhancement 340409, but have added a comment
>> indicating my interest for a solution.
>>
>> I've read the "Comment serialization" thread and understand the creative
>> solution you implemented. For my case, I am not sure what I would need to
>> extend/override in order to detect/handle the problematic/invalid regions
>> that cannot be serialized.
>>
>> Mary
>>
>> "Ed Willink" <ed@willink.me.uk> wrote in message
>> news:j8daqr$9cd$1@news.eclipse.org...
>>> Hi Mary
>>>
>>> Vote for or contribute a solution to
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=340409.
>>>
>>> With the new serializer structure, I suspect that it's not that
>>> difficult.
>>>
>>> But even without fixing the enhancement request, you could encapsulate
>>> the bad input regions as distinctive comments on dummy valid input and
>>> use the comment serialization discussed in the "Comment serialization"
>>> thread "news://news.eclipse.org:119/j7s40a$s6b$1@news.eclipse.org.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>> On 27/10/2011 23:07, Mary Komor wrote:
>>>> Hi,
>>>>
>>>> We currently have a working Xtext editor for our DSL and are in the
>>>> process of creating a graphical editor to allow for editing of the same
>>>> Xtext resource. We are hoping to use the Xtext Serializer to write out
>>>> the model as text when the user saves the content of the graphical
>>>> editor. However, the model may not always be valid when the save
>>>> command is invoked, but we would still want to save the current state
>>>> of the model (e.g. user needs to close the editor but is not able to
>>>> finish creating a valid model). After reading questions/answers posted
>>>> to this forum, my understanding is that the Xtext Serializer will not
>>>> be able to serialize an invalid/incomplete model, is that correct? If
>>>> so, what are my options in this case? Is writing my own custom
>>>> serializer the only option?
>>>>
>>>> Mary
>>>
Re: Serializing invalid content? [message #754506 is a reply to message #753759] Wed, 02 November 2011 19:29 Go to previous message
Mary Komor is currently offline Mary KomorFriend
Messages: 61
Registered: July 2009
Member
Yes, loading invalid content is going to be interesting... the resulting AST
may be completely wrong. In the case of the text editor, the user would
still see the text and can correct the errors... in the case of the
graphical editor, it is akin to asking the user to work off the Outline view
where the content could be completely incorrect. For example, a missing
semi-colon at the end of a statement could throw the way parser off. What
are some strategies to deal with such scenarios?

Mary

"Ed Willink" <ed@willink.me.uk> wrote in message
news:j8eid2$sp3$1@news.eclipse.org...
> Hi
>
> I think you actually need both levels of fixes.
>
> When creating, you should provide wrappers for invalid content so that the
> user can save.
>
> When loading, you should provide wrappers for invalid content so that the
> user can load. (A new editor version/meta-model version/tooling
> enhancement may make a previously 'correct' model invalid.)
>
> Regards
>
> Ed Willink
>
> On 28/10/2011 11:36, Henrik Lindberg wrote:
>> On 10/28/11 6:52 AM, Mary Komor wrote:
>>> Hi Henrik,
>>>
>>> Thanks for the suggestions!
>>>
>>> Saving as XML is not an option as we also want our users to be able to
>>> edit the same file in the text format in other text editor... primarily
>>> in our Xtext-based editor.
>>>
>> The idea was to save as XML as a sort of "persist editor state" - a
>> reconciliation would be needed at some future point.
>>
>> Ed's suggestions would be the best way IMO - don't let the user create
>> something that is broken.
>>
>> - henrik
>
Previous Topic:Name validation
Next Topic:eclipse/xtend2: define a folder as source in buildpath
Goto Forum:
  


Current Time: Fri Apr 26 05:49:37 GMT 2024

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

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

Back to the top