nitc :: ANode :: accept_pretty_printer
self
using a PrettyPrinterVisitor
# Start visit of `self` using a `PrettyPrinterVisitor`
private fun accept_pretty_printer(v: PrettyPrinterVisitor) is abstract
src/pretty.nit:320,2--321,71
redef fun accept_pretty_printer(v) do
v.add text.trim
v.current_token = next_token
end
src/pretty.nit:349,2--352,4
redef fun accept_pretty_printer(v) do v.visit first_token
src/pretty.nit:371,2--58
redef fun accept_pretty_printer(v) do
for n_propdef in n_propdefs do
v.catch_up n_propdef
if n_propdef.n_doc != null or not v.can_inline(n_propdef) then
if v.skip_empty and n_propdef != n_propdefs.first then v.addn
v.visit n_propdef
if v.skip_empty and n_propdef != n_propdefs.last then v.addn
else
v.visit n_propdef
end
end
end
src/pretty.nit:668,2--680,4
redef fun accept_pretty_printer(v) do
v.catch_up start_token
v.visit n_moduledecl
if not n_imports.is_empty then
if v.skip_empty then v.addn
for n_import in n_imports do
v.catch_up n_import
v.visit n_import
end
end
if not n_extern_code_blocks.is_empty then
v.addn
for n_extern_block in n_extern_code_blocks do
v.catch_up n_extern_block
v.visit n_extern_block
v.addn
if n_extern_block != n_extern_code_blocks.last then v.addn
end
if not n_classdefs.is_empty then v.addn
end
if not n_classdefs.is_empty then
if v.skip_empty then v.addn
for n_classdef in n_classdefs do
v.catch_up n_classdef
v.visit n_classdef
if n_classdef != n_classdefs.last then v.addn
end
end
assert v.indent == 0
end
src/pretty.nit:553,2--590,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwimport
if can_inline then
v.adds
v.visit_list n_extern_calls
else
v.forcen
v.indent += 1
v.addt
v.indent -= 1
v.visit_list n_extern_calls
end
v.adds
end
src/pretty.nit:1058,2--1074,4
redef fun accept_pretty_printer(v) do
if n_in_language != null then
v.visit n_in_language
v.adds
end
v.visit n_extern_code_segment
end
src/pretty.nit:1127,2--1134,4
redef fun accept_pretty_printer(v) do for comment in n_comment do v.visit comment
src/pretty.nit:487,2--82
redef fun accept_pretty_printer(v) do
v.adds
v.consume "is"
if v.can_inline(self) then
v.adds
for n_item in n_items do
v.visit n_item
if n_item != n_items.last then
v.add ", "
end
end
if not was_inline then
v.finish_line
if v.current_token isa TKwend then v.skip
end
else
v.forcen
v.indent += 1
for n_item in n_items do
v.addt
v.visit n_item
v.finish_line
if n_item != n_items.last then
if was_inline then
v.forcen
else
v.addn
end
end
end
v.indent -= 1
end
end
src/pretty.nit:494,2--526,4
redef fun accept_pretty_printer(v) do
if v.skip_empty then
super
else
v.add text
v.current_token = next_token
end
end
src/pretty.nit:360,2--367,4
redef fun accept_pretty_printer(v) do
if is_adoc then
v.addt
super
v.forcen
return
end
if is_licence then
super
v.forcen
if is_last_in_group then v.addn
return
end
if is_orphan then
v.addn
v.addt
super
v.forcen
v.addn
return
end
if is_inline then
if next_token isa TComment and is_first_in_group then v.addn
v.addt
super
v.forcen
var prev_token = self.prev_token
if prev_token isa TComment and prev_token.is_inline and is_last_in_group then v.addn
return
end
super
if not v.skip_empty then v.forcen
end
src/pretty.nit:413,2--449,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
if can_inline then
super
else
var text = text.substring(2, text.length - 4)
var lines = text.r_trim.split("\n")
if text.is_empty then
v.add "`\{`\}"
else
v.add "`\{"
if not lines.first.trim.is_empty then
v.forcen
lines.first.l_trim
v.indent += 1
v.addt
v.indent -= 1
end
for line in lines do
v.add line.r_trim
v.forcen
end
v.addt
v.add "`\}"
end
v.current_token = next_token
end
end
src/pretty.nit:1151,2--1184,4
redef fun accept_pretty_printer(v) do
var before = v.indent
var can_inline = v.can_inline(self)
if can_inline and not n_expr.is_empty then
v.visit n_expr.first
v.finish_line
else
for nexpr in n_expr do
var expr_inline = v.can_inline(nexpr)
if not expr_inline and nexpr != n_expr.first then v.addn
v.catch_up nexpr
v.addt
v.visit nexpr
v.finish_line
v.addn
if not expr_inline and nexpr != n_expr.last then v.addn
end
end
assert v.indent == before
end
src/pretty.nit:1195,2--1216,4
redef fun accept_pretty_printer(v) do v.visit n_kwabort
src/pretty.nit:1923,2--56
redef fun accept_pretty_printer(v) do
var before = v.indent
var can_inline = v.can_inline(self)
v.visit n_kwif
v.adds
if v.can_inline(n_expr) then
v.visit n_expr
v.adds
else
v.visit n_expr
v.forcen
v.addt
end
# skip comments before `then` token
while not v.current_token isa TKwthen do v.skip
v.consume "then"
var n_else = self.n_else
if can_inline then
v.adds
if n_then != null then v.visit n_then
if has_else(v) then
n_else.force_inline = true
v.adds
v.consume "else"
v.adds
v.visit n_else
else if n_then == null then
v.add "end"
end
v.skip_to last_token.last_real_token_in_line
else
v.finish_line
if was_inline then
v.forcen
else if not v.skip_empty and n_then != null and
n_then.was_inline and
n_then.location.line_end == location.line_start then
v.forcen # Xymus fucking syntax
else
v.addn
end
v.indent += 1
if n_then != null then
if n_then isa ABlockExpr then
n_then.force_block = true
v.visit n_then
else
v.addt
v.visit n_then
if n_then.was_inline then
v.forcen
else
v.addn
end
end
end
v.consume_comments
# FIXME: for some unknown reasons, has_else can be true even if
# there is no `else` keyword but a `end` instead.
if has_else(v) and v.current_token isa TKwelse then
v.indent -= 1
v.addt
v.consume "else"
if n_else isa AIfExpr then
n_else.force_block = true
v.adds
v.visit n_else
else
v.finish_line
if was_inline then
v.forcen
else
v.addn
end
v.indent += 1
if n_else isa ABlockExpr then
n_else.force_block = true
v.visit n_else
else
v.addt
v.visit n_else
if n_else.was_inline then
v.forcen
else
v.addn
end
end
if last_token isa TKwend then
v.catch_up last_token
v.indent -= 1
v.addt
v.consume "end"
else
v.indent -= 1
v.addt
v.add "end"
end
end
else
if last_token.location >= v.current_token.location then v.catch_up last_token
v.indent -= 1
v.addt
v.add "end"
if v.current_token isa TKwend then v.skip
end
end
assert v.indent == before
end
src/pretty.nit:1232,2--1351,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwassert
if n_id != null then
v.adds
v.visit n_id
v.consume ":"
end
v.adds
v.visit n_expr
var n_else = self.n_else
if n_else != null then
v.adds
v.consume "else"
if can_inline then
v.adds
v.visit n_else
else
v.addn
v.indent += 1
if n_else isa ABlockExpr then
n_else.force_block = true
v.visit n_else
v.indent -= 1
v.addt
v.visit n_else.n_kwend
else
v.addt
v.visit n_else
v.forcen
v.indent -= 1
v.addt
v.add "end"
end
end
end
end
src/pretty.nit:1829,2--1870,4
redef fun accept_pretty_printer(v) do v.visit n_kwnull
src/pretty.nit:2066,2--55
redef fun accept_pretty_printer(v) do
v.visit n_kwsuper
if not n_args.n_exprs.is_empty then
if is_stmt and n_args.n_exprs.length == 1 then
v.adds
if v.current_token isa TOpar then v.skip
v.visit n_args.n_exprs.first
if v.current_token isa TCpar then v.skip
else
v.visit_args n_args.n_exprs
end
end
end
src/pretty.nit:1891,2--1904,4
redef fun accept_pretty_printer(v) do
v.visit n_doc
v.visit n_kwmodule
v.adds
v.visit n_name
if n_annotations != null then
var annot_inline = v.can_inline(n_annotations)
v.visit n_annotations
if not annot_inline then
if v.current_token isa TKwend then
v.consume "end"
v.finish_line
else
v.add "end"
end
end
end
v.finish_line
if v.skip_empty then v.addn
end
src/pretty.nit:604,2--626,4
redef fun accept_pretty_printer(v) do
if not n_visibility isa APublicVisibility then
v.visit n_visibility
v.adds
end
v.visit n_kwimport
v.adds
v.visit n_name
v.finish_line
if v.skip_empty then v.addn
end
src/pretty.nit:651,2--662,4
redef fun accept_pretty_printer(v) do
v.visit n_kwimport
v.adds
v.visit n_kwend
v.finish_line
if v.skip_empty then v.addn
end
src/pretty.nit:641,2--647,4
redef fun accept_pretty_printer(v) do
v.visit n_kwabstract
v.adds
v.visit n_kwclass
end
src/pretty.nit:755,2--759,4
redef fun accept_pretty_printer(v) do
v.visit n_kwextern
v.adds
v.visit n_kwclass
end
src/pretty.nit:763,2--767,4
redef fun accept_pretty_printer(v) do v.visit n_type
src/pretty.nit:547,2--53
redef fun accept_pretty_printer(v) do
if n_visibility != null and not n_visibility isa APublicVisibility then
v.visit n_visibility
v.adds
end
v.visit n_atid
v.visit_args n_args
end
src/pretty.nit:536,2--543,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
if not can_inline then
if (self isa ABinopExpr and bin_expr1 isa ABinopExpr) or
(self isa AAndExpr and (bin_expr1 isa AAndExpr or bin_expr1 isa AOrExpr)) or
(self isa AOrExpr and (bin_expr1 isa AAndExpr or bin_expr1 isa AOrExpr))
then
bin_expr1.force_block = true
end
end
v.visit bin_expr1
v.adds
v.consume bin_op
if can_inline then
v.adds
v.visit bin_expr2
else
v.forcen
v.indent += 1
v.addt
v.indent -= 1
v.visit bin_expr2
end
end
src/pretty.nit:1971,2--1997,4
redef fun accept_pretty_printer(v) do
super
v.visit n_kwvar
v.adds
v.visit n_id2
if n_type != null then
v.consume ":"
v.adds
v.visit n_type
end
if n_expr != null then
v.adds
v.consume "="
v.adds
v.visit n_expr
end
var annot_inline = visit_annotations(v, n_annotations)
visit_block(v, n_block, annot_inline)
v.finish_line
v.addn
end
src/pretty.nit:908,2--931,4
redef fun accept_pretty_printer(v) do
v.visit_recv n_expr
v.visit n_id
end
src/pretty.nit:1763,2--1766,4
redef fun accept_pretty_printer(v) do
v.visit n_doc
var can_inline = v.can_inline(self)
if not n_visibility isa APublicVisibility then
v.visit n_visibility
v.adds
end
if n_kwredef != null then
v.visit n_kwredef
v.adds
end
v.visit n_classkind
v.adds
v.visit n_qid
if not n_formaldefs.is_empty then
v.consume "["
v.visit_list n_formaldefs
v.consume "]"
end
if n_extern_code_block != null then
v.adds
v.visit n_extern_code_block
end
if can_inline then
v.adds
if not n_propdefs.is_empty then
for n_superclass in n_propdefs do
v.visit n_superclass
v.adds
end
end
else
v.finish_line
if v.skip_empty then v.addn
v.indent += 1
super
v.catch_up n_kwend
v.indent -= 1
end
v.visit n_kwend
v.finish_line
if v.skip_empty then v.addn
assert v.indent == 0
end
src/pretty.nit:684,2--736,4
redef fun accept_pretty_printer(v) do
super
v.visit n_kwsuper
v.adds
v.visit n_type
visit_annotations(v, n_annotations)
v.finish_line
v.addn
end
src/pretty.nit:1012,2--1020,4
redef fun accept_pretty_printer(v) do v.visit n_methid
src/pretty.nit:1086,2--55
redef fun accept_pretty_printer(v) do v.visit n_type
src/pretty.nit:1090,2--53
redef fun accept_pretty_printer(v) do
# TODO: Handle extern annotations
var before = v.indent
super
if n_kwinit != null then v.visit n_kwinit
if n_kwmeth != null then v.visit n_kwmeth
if n_kwnew != null then v.visit n_kwnew
if not n_methid == null then
v.adds
v.visit n_methid
end
v.visit n_signature
var annot_inline = visit_annotations(v, n_annotations)
if n_extern_calls != null or n_extern_code_block != null then
v.adds
if n_extern_calls != null then v.visit n_extern_calls
if n_extern_code_block != null then v.visit n_extern_code_block
end
visit_block(v, n_block, annot_inline)
v.addn
assert v.indent == before
end
src/pretty.nit:961,2--988,4
redef fun accept_pretty_printer(v) do
if not v.break_strings then
# n_string.force_inline = true
v.visit n_string
return
end
if v.can_inline(self) then
n_string.force_inline = true
v.visit n_string
else
var text = n_string.text
var i = 0
while i < text.length do
v.add text[i].to_s
if v.max_size > 0 and v.current_length >= v.max_size and i <= text.length - 3 then
v.add "\" +"
if was_inline then
v.forcen
else
v.addn
end
v.indent += 1
v.addt
v.indent -= 1
v.add "\""
end
i += 1
end
v.current_token = n_string.next_token
end
end
src/pretty.nit:2114,2--2148,4
redef fun accept_pretty_printer(v) do
for n_expr in n_exprs do
if not v.break_strings then
n_expr.force_inline = true
end
v.visit n_expr
end
end
src/pretty.nit:2152,2--2159,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit_recv n_expr
if not n_expr isa AImplicitSelfExpr and not can_inline then
v.forcen
v.addt
end
v.visit n_qid
if not n_args.n_exprs.is_empty then
if is_stmt and n_args.n_exprs.length == 1 then
v.adds
if v.current_token isa TOpar then v.skip
v.visit n_args.n_exprs.first
if v.current_token isa TCpar then v.skip
else
v.visit_args n_args.n_exprs
end
end
end
src/pretty.nit:1591,2--1612,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwdo
if can_inline then visit_loop_inline v else visit_loop_block v
end
src/pretty.nit:1504,2--1508,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwwhile
v.adds
v.visit n_expr
v.adds
v.visit n_kwdo
if can_inline then visit_loop_inline v else visit_loop_block v
end
src/pretty.nit:1487,2--1495,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwloop
if can_inline then visit_loop_inline v else visit_loop_block v
end
src/pretty.nit:1474,2--1478,4
redef fun accept_pretty_printer(v) do
var can_inline = v.can_inline(self)
v.visit n_kwfor
v.adds
for n_group in n_groups do
v.visit n_group
if n_group != n_groups.last then v.add ", "
end
v.adds
v.visit n_kwdo
if can_inline then visit_loop_inline v else visit_loop_block v
end
src/pretty.nit:1517,2--1531,4
redef fun accept_pretty_printer(v) do
v.visit n_block
if v.skip_empty then v.addn
end
src/pretty.nit:1005,2--1008,4