Serialize (pretty-print) - Xtext or TCS? [message #24283] |
Sun, 14 December 2008 18:09  |
Eclipse User |
|
|
|
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 #26192 is a reply to message #26152] |
Fri, 16 January 2009 11:44  |
Eclipse User |
|
|
|
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...
>
|
|
|
Powered by
FUDForum. Page generated in 0.02566 seconds