[Formatter2] append newLine + spaces [message #1803049] |
Thu, 21 February 2019 13:20  |
ayman salah Messages: 131 Registered: June 2015 |
Senior Member |
|
|
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 10:39] Report message to a moderator
|
|
|
|
Re: [Formatter2] append newLine + spaces [message #1803161 is a reply to message #1803055] |
Sun, 24 February 2019 10:37   |
ayman salah Messages: 131 Registered: June 2015 |
Senior Member |
|
|
I know that I am supposed to use the indent feature.
But the indent feature uses the tab width set by the user.
I want to be able to set the indent width for each type of list to match the (list type + space + open bracket) width.
For example:
greetingsList (
greeting g1;
greeting g2;
);
asdList (
asd a1;
asd a2;
);
You get me?
[Updated on: Sun, 24 February 2019 10:38] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02521 seconds