[Formatter2] append newLine + spaces [message #1803049] |
Thu, 21 February 2019 08:20  |
Eclipse User |
|
|
|
Hi all,
I am trying to achieve alignment with list opening bracket, but I can't.
Here is how I am trying:
Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
DSL returns XTDSL:
models+=Model*
;
Model returns XTModel:
{XTModel} 'startList' '(' greetings+=Greeting*')'';';
Greeting returns XTGreeting:
'list' ids_list=identifier_list ':' 'endlist' ';';
identifier_list returns XTIdentifierList:
ids+=identifier (',' ids+=identifier)*
;
identifier returns XTIdentifier:
{XTIdentifier} ID
;
Formatter:
def dispatch void format(XTDSL xtdsl, extension IFormattableDocument document) {
xtdsl.models.forEach[format]
}
def dispatch void format(XTModel xtmodel, extension IFormattableDocument document) {
xtmodel.greetings.forEach[format; append[newLine]]
xtmodel.regionFor.keyword("startList").append[oneSpace]
xtmodel.regionFor.keyword("(").append[newLine]
xtmodel.regionFor.keyword(")").prepend[noSpace]
xtmodel.regionFor.keyword(";").prepend[noSpace]
xtmodel.append[newLine]
alignGreetingsOnOpenBracket(xtmodel.greetings, document)
}
def void alignGreetingsOnOpenBracket(EList<XTGreeting> greetings, extension IFormattableDocument document) {
val precedingString = "startList ("
for (greeting : greetings) {
greeting.prepend[space = Strings.repeat(" ", precedingString .length); highPriority]
}
}
What happens is:
startList (
list A : endlist;
list B : endlist;
list C : endlist;
);
While I expect:
startList (
list A : endlist;
list B : endlist;
list C : endlist;
);
Why does append[newLine] result in ignoring any spaces added after (newLine = newLine and spaces ignored)?
I know that I can use interior[indent], but that would result in indenting using whatever tab width is set, which is not necessarily going to match the width of "startList (".
[Updated on: Sun, 24 February 2019 05:39] by Moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05520 seconds