Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [xtext-dev] Persisting xtext document information

Hi Peter,

yes, it's possible to store Xtext as ASTs in a model repository, but I wouldn't recommend it, because the AST, as the name Abstract Syntax Tree suggests, does not contain any information about whitespaces, line wraps and comments in your model. Therefore, you'd have to persist them separately.

You might want to look at the OCLinEcore Editor from Eclipse OCL. It can open Ecore files (XMI) and make the content available as text in an Xtext editor.

Are you aware that Xtext ships with two serializers? The old one "ParseTreeConstructorFragment" has been superseded by the "SerializerFragment". 

The new serializer will not produce a different syntax as long as it still has the old whitespace. And even with lost whitespace, the serializer will only do changes that your grammar explicitly allows: For example, if you use unordered groups, the order of the elements is usually not stored in your AST, and therefore the serializer can not recreate the old order if no whitespace information is available. 

If you want to go further in this direction, you should also think about how you want to persist documents with syntax errors. Since these documents can not be parsed completely you won't have a complete AST. Consequently, if you only persist the AST, the user will loose all parts of the document that are involved in syntax errors. If Syntax errors are so severe that the parser can't recover, the user will use the complete tail of the document.

regards,
  Moritz

On Jan 18, 2013, at 10:44 AM, Peter Pedron <Peter.Pedron@xxxxxxxxxxxx> wrote:

Hello xtext developers,
 
with EMFStore it is possible to persist and share EMF model instances.
I was wondering, whether it is possible, feasible or imaginable, to store and restore xtext document structure information (as far as I know this is stored in the AST) along with the model instance, in order that the original xtext document which generated a certain model instance can be restored when loading a model from the store. As you already might have understood, I try to avoid of being dependent on the generated xtext Serializer of the grammar. The use of the standard grammar serializer, when loading a model from an EMFStore, would guarantee the right semantic in the created xtext document, but might produce a different syntax and order of statements compared to the xtext document which was originally used to create the model.
 
Looking forward to your answers and opinions about this topic.
 
Peter Pedron
 
 
_______________________________________________
xtext-dev mailing list
xtext-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/xtext-dev


Back to the top