|
|
|
Re: Formatting multiple parser rules within curly brackets [message #1791056 is a reply to message #1790779] |
Fri, 22 June 2018 09:32 |
Alex Mising name Messages: 149 Registered: March 2010 |
Senior Member |
|
|
I have managed to get formatting to work as desired. As per the github issue response, I now prepend new lines for every semantic region in the indented block. However, I have found an edge case which does not work: comments before the closing brace are not indented (they seem to follow the indentation level of the brace that follows, rather than the semantic region before the comment).
Example of sample input:
greetings {
// hello...
Hello X !
Hello Y ! Hello Z !
// ...world!
}
Expected formatting:
greetings {
// hello...
Hello X !
Hello Y !
Hello Z !
// ...world!
}
Actual formatting:
greetings {
// hello...
Hello X !
Hello Y !
Hello Z !
// ...world!
}
How can I tell my formatter that indentation applies to comments as well? As per Christian's reply in the github issue I have now:
def dispatch void format(Model model, extension IFormattableDocument document) {
model.regionFor.keyword("{").append[newLine]
model.regionFor.keyword("}").prepend[newLine]
interior(
model.regionFor.keyword("{"),
model.regionFor.keyword("}")
)[indent]
for (greeting : model.greetings) {
greeting.prepend[newLine]
}
// HOW DO I PREPEND NEW LINE TO COMMENTS?
}
Interestingly, this only occurs for comments at the very end of the block, before the closing brace. So other comments seem to follow the indentation of the semantic regions around them.
[Updated on: Fri, 22 June 2018 09:34] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03230 seconds