using this minimalistic grammar
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl ""
Model:
(includes+=Include)*
(greetings+=Element)+;
Element:
Greeting | Farewell
;
Greeting:
'Hello' name=ID '!';
Farewell:
'Bye' name=ID '!'
;
Include:
"include" name=ID";"
;
and this formatter
public class MyDslFormatter extends AbstractDeclarativeFormatter {
protected void configureFormatting(FormattingConfig c) {
MyDslGrammarAccess f = (MyDslGrammarAccess) getGrammarAccess();
c.setLinewrap(2).around(f.getElementRule());
}
}
the formatter works only correctly if at least one include is defined. I don't understand why. Can somebody shed some light on this?
The results after formatting are:
include Name ;
Hello rob !
Hello Name !
Bye rob !
and
Hello rob ! Hello Name ! Bye rob !