Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Serialize (pretty-print) - Xtext or TCS?
Serialize (pretty-print) - Xtext or TCS? [message #24283] Sun, 14 December 2008 18:09 Go to next message
Eclipse UserFriend
Hi,
is there a way to do model-to-text transformation with Xtext
programatically? If not, TCS surely can do it - but is it available at
least as source yet?
Thanks for the reply in advance!
thSoft
Re: Serialize (pretty-print) - Xtext or TCS? [message #24324 is a reply to message #24283] Mon, 15 December 2008 03:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dennis,

yes, TMF Xtext allows that. We are currently working on the API to
specify how whitespaces should be handled. It's pretty much finished and
will be included in M4 (dec. 29th).

Cheers,
Sven

Dennis Harmath schrieb:
> Hi,
> is there a way to do model-to-text transformation with Xtext
> programatically? If not, TCS surely can do it - but is it available at
> least as source yet?
> Thanks for the reply in advance!
> thSoft
>
Re: Serialize (pretty-print) - Xtext or TCS? [message #24407 is a reply to message #24324] Mon, 15 December 2008 06:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dennis,

Xtext provides an EMF Resource implementation, you can use that to save
models disk (serialize them to their textual format based on the grammar
you specified).

> yes, TMF Xtext allows that. We are currently working on the API to
> specify how whitespaces should be handled. It's pretty much finished and
> will be included in M4 (dec. 29th).

This is an example of the API Sven mentioned:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org .eclipse.xtext/plugins/org.eclipse.xtext/src/org/eclipse/xte xt/xtext/XtextFormattingTokenSerializer.java?revision=1.1&am p;root=Modeling_Project&view=markup

It defines whitespaces, linewraps and indentation for Xtext grammars itself.

regards,
Moritz
Re: Serialize (pretty-print) - Xtext or TCS? [message #26152 is a reply to message #24407] Thu, 15 January 2009 18:49 Go to previous messageGo to next message
Eclipse UserFriend
Great news!
So that M4 is out, what is the exact way of serializing a model?
Something like this:

XtextResource resource;
resource.setTokenSerializer(new XtextFormattingTokenSerializer());
resource.doSave(new FileOutputStream(myFile), Collections.EMPTY_MAP);

...as I figured out so far...
Re: Serialize (pretty-print) - Xtext or TCS? [message #26192 is a reply to message #26152] Fri, 16 January 2009 11:44 Go to previous message
Eclipse UserFriend
Hey,

you can use the RuntimeConfig of your DSL to configure a formatter for
it. This is Xtext's own RuntimeConfig, for example:

public class XtextRuntimeConfig extends AbstractXtextRuntimeConfig {
public Set<IServiceRegistration> registrations() {
Set<IServiceRegistration> inherited = scope(IXtext.SCOPE)
.with(IScopeProvider.class, XtextScopeProvider.class)
.with(ILinker.class, XtextLinker.class)
.with(ILinkingService.class, XtextLinkingService.class)
.with(ITransientValueService.class, XtextTransientValueService.class)
.with(ITokenSerializer.class, XtextFormattingTokenSerializer.class)
.registrations();
inherited.addAll(super.registrations());
return inherited;
}
}


Then XtextResources will use this formatter... there is no further
special treatment required for the resource.

Please note, that currently all information that is not stored in the
AST (your model) is not serialized when using the formatter. These are
whitespaes/linebrakes and comments.

This snipped might also be interesting, but don't rely on the API to
stay that way...
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org .eclipse.xtext/plugins/org.eclipse.xtext/src/org/eclipse/xte xt/parsetree/reconstr/SerializerUtil.java?revision=1.3&r oot=Modeling_Project&view=markup

hth,
Moritz



Dennis Harmath wrote:
> Great news!
> So that M4 is out, what is the exact way of serializing a model?
> Something like this:
>
> XtextResource resource;
> resource.setTokenSerializer(new XtextFormattingTokenSerializer());
> resource.doSave(new FileOutputStream(myFile), Collections.EMPTY_MAP);
>
> ..as I figured out so far...
>
Previous Topic:[TCS] dc#title going in "dc#title" going out
Next Topic:[Announce] TMF XTEXT 0.7.0 I200901151317 is available
Goto Forum:
  


Current Time: Fri May 09 17:39:44 EDT 2025

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

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

Back to the top