Formatting comma-separated list with new line & indent [message #1849586] |
Wed, 26 January 2022 10:36 |
Carl Weathers Messages: 2 Registered: January 2022 |
Junior Member |
|
|
Hi,
I'm trying to write a formatter for a grammar rule like this:
Block:
{Block} 'Block'
defs+=Def (',' defs+=Def)*
;
Def:
name=ID
;
I would like to have this formatted like so:
All the Defs should be on a new line, and indented.
I can get it to work if my syntax for the Block rule has a "end" token, using the formatter's "interior" API (I also didn't have comma separators back then). But now I cannot make it work.
Here is an example of many I tried which I would assume should work, but doesn't:
def dispatch void format(Block block, extension IFormattableDocument document) {
block.regionFor.keyword("Block").append[newLine]
block.defs.tail.forEach [ def | def.prepend[newLine]]
block.defs.forEach[def|def.prepend[indent]]
}
What this gives me is:
Block
Alpha ,
Beta ,
Gamma
So, no indent, and also a whitespace before the comma I would like to remove if possible.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03410 seconds