nitc :: ALoopHelper :: defaultinit
# Used to factorize work on loops.
private class ALoopHelper
super AExpr
fun loop_block: nullable ANode is abstract
fun loop_label: nullable ANode is abstract
fun visit_loop_block(v: PrettyPrinterVisitor) do
var n_block = loop_block
v.finish_line
v.addn
v.indent += 1
if n_block isa ABlockExpr then
n_block.force_block = true
v.visit n_block
v.catch_up n_block.n_kwend
v.indent -= 1
v.addt
v.visit n_block.n_kwend
else
v.addt
v.visit n_block
v.addn
v.indent -= 1
v.addt
v.add "end"
end
if loop_label != null then
v.adds
v.visit loop_label
end
end
fun visit_loop_inline(v: PrettyPrinterVisitor) do
var n_block = loop_block
v.adds
if n_block isa ABlockExpr then
if n_block.n_expr.is_empty then
v.visit n_block.n_kwend
else
v.visit n_block.n_expr.first
v.current_token = n_block.n_kwend
v.skip
end
else
v.visit n_block
if v.current_token isa TKwend then v.skip
end
if loop_label != null then
v.adds
v.visit loop_label
end
end
redef fun is_inlinable do
var n_block = loop_block
if not super then return false
if n_block isa ABlockExpr and not n_block.is_inlinable then return false
if not collect_comments.is_empty then return false
return true
end
end
src/pretty.nit:1401,1--1466,3