How to format nested loops ? [message #1800924] |
Wed, 09 January 2019 20:39 |
Charalampos Alexopoulos Messages: 13 Registered: July 2012 |
Junior Member |
|
|
Hi all
I am trying to format nested loops but i fail all the time, given my lack of experience it is not a surprise. Can someone help me?
Thank you in advance
Here is my simplified grammar
Package:
Statements;
Statements:
(statements+=Statement)+
;
Statement:
ForStatement
;
ForStatement:
for="for("")" block=Child
;
Child:
{Children} (";"
| "{" (children+=Child)* "}"
| it=Statement)
;
and here is the Formatter code
def dispatch void format(Statements statements, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
for (statement : statements.statements) {
statement.format
}
}
def dispatch void format(ForStatement forStatement, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
forStatement.block.format
}
def dispatch void format(Children children, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
val open = children.regionFor.keyword("{")
val close = children.regionFor.keyword("}")
open.append[newLine]
open.prepend[newLine]
close.append[newLine]
close.prepend[newLine]
interior(open, close, [indent])
This is what i expect
for()
{
for()
{
for()
{
}
}
}
and this is what i get
|
|
|
Re: How to format nested loops ? [message #1800925 is a reply to message #1800924] |
Wed, 09 January 2019 20:59 |
|
the simply straight forward approach does not work?
def dispatch void format(Children children, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
val open = children.regionFor.keyword("{")
val close = children.regionFor.keyword("}")
open.append[newLine]
open.prepend[newLine]
close.append[newLine]
close.prepend[newLine]
interior(open, close, [indent])
// you dont format the content, no wonder it does not work
for (subchild : children.children) {
subchild.format
}
// nor the it
children.it?.format
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04232 seconds