Start visit of self using a PrettyPrinterVisitor

Property definitions

nitc :: pretty $ ANode :: accept_pretty_printer
	# Start visit of `self` using a `PrettyPrinterVisitor`
	private fun accept_pretty_printer(v: PrettyPrinterVisitor) is abstract
src/pretty.nit:320,2--321,71

nitc :: pretty $ Token :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.add text.trim
		v.current_token = next_token
	end
src/pretty.nit:349,2--352,4

nitc :: pretty $ Prod :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit first_token
src/pretty.nit:371,2--58

nitc :: pretty $ AClassdef :: accept_pretty_printer
	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

nitc :: pretty $ AModule :: accept_pretty_printer
	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

nitc :: pretty $ AFormaldef :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_id

		if n_type != null then
			v.consume ":"
			v.adds
			v.visit n_type
		end
	end
src/pretty.nit:771,2--779,4

nitc :: pretty $ ASignature :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		if not n_params.is_empty then
			v.consume "("
			v.visit_list n_params
			v.consume ")"
		end

		if n_type != null then
			v.consume ":"
			v.adds
			v.visit n_type
		end
	end
src/pretty.nit:1026,2--1038,4

nitc :: pretty $ AParam :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_id

		if n_type != null then
			v.consume ":"
			v.adds
			v.visit n_type
		end

		if n_dotdotdot != null then v.visit n_dotdotdot
	end
src/pretty.nit:1042,2--1052,4

nitc :: pretty $ AType :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		if n_kwnullable != null then
			v.visit n_kwnullable
			v.adds
		end

		v.visit n_qid

		if not n_types.is_empty then
			v.consume "["
			v.visit_list n_types
			v.consume "]"
		end
	end
src/pretty.nit:783,2--796,4

nitc :: pretty $ AForGroup :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		for n_id in n_ids do
			v.visit n_id
			if n_id != n_ids.last then v.add ", "
		end

		v.adds
		v.consume "in"
		v.adds
		v.visit n_expr
	end
src/pretty.nit:1535,2--1545,4

nitc :: pretty $ AModuleName :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		for path in n_path do
			v.visit path
			v.add "::"
		end

		v.visit n_id
	end
src/pretty.nit:630,2--637,4

nitc :: pretty $ AExternCalls :: accept_pretty_printer
	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

nitc :: pretty $ AInLanguage :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwin
		v.adds
		v.visit n_string
	end
src/pretty.nit:1143,2--1147,4

nitc :: pretty $ AExternCodeBlock :: accept_pretty_printer
	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

nitc :: pretty $ ADoc :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do for comment in n_comment do v.visit comment
src/pretty.nit:487,2--82

nitc :: pretty $ AAnnotations :: accept_pretty_printer
	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

nitc :: pretty $ TEol :: accept_pretty_printer
	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

nitc :: pretty $ TComment :: accept_pretty_printer
	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

nitc :: pretty $ TExternCodeSegment :: accept_pretty_printer
	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

nitc :: pretty $ APropdef :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_doc
		v.addt

		if not n_visibility isa nullable APublicVisibility then
			v.visit n_visibility
			v.adds
		end

		if n_kwredef != null then
			v.visit n_kwredef
			v.adds
		end
	end
src/pretty.nit:802,2--815,4

nitc :: pretty $ ABlockExpr :: accept_pretty_printer
	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

nitc :: pretty $ AVardeclExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwvar
		v.adds
		v.visit n_id

		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
	end
src/pretty.nit:1796,2--1813,4

nitc :: pretty $ AAbortExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit n_kwabort
src/pretty.nit:1923,2--56

nitc :: pretty $ AIfExpr :: accept_pretty_printer
	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

nitc :: pretty $ AAssertExpr :: accept_pretty_printer
	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

nitc :: pretty $ AArrayExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.consume "["
		v.visit_list n_exprs
		if n_type != null then
			v.consume ":"
			v.adds
			v.visit n_type
		end
		v.consume "]"
	end
src/pretty.nit:2079,2--2088,4

nitc :: pretty $ ANullExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit n_kwnull
src/pretty.nit:2066,2--55

nitc :: pretty $ AParExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_opar
		v.visit n_expr
		v.visit n_cpar
	end
src/pretty.nit:2071,2--2075,4

nitc :: pretty $ AOnceExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwonce
		v.adds
		v.visit n_expr
	end
src/pretty.nit:1913,2--1917,4

nitc :: pretty $ ANewExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		var can_inline = v.can_inline(self)
		v.visit n_kwnew
		v.adds
		v.visit n_type

		if n_qid != null then
			v.consume "."

			if not can_inline then
				v.forcen
				v.indent += 1
				v.addt
				v.indent -= 1
			end

			v.visit n_qid
		end

		v.visit_args n_args.n_exprs
	end
src/pretty.nit:1735,2--1755,4

nitc :: pretty $ AModuledecl :: accept_pretty_printer
	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

nitc :: pretty $ ANoImport :: accept_pretty_printer
	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

nitc :: pretty $ AExternClasskind :: accept_pretty_printer
	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

nitc :: pretty $ ABraMethid :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_obra
		v.visit n_cbra
	end
src/pretty.nit:1708,2--1711,4

nitc :: pretty $ AAssignMethid :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_id
		v.visit n_assign
	end
src/pretty.nit:1701,2--1704,4

nitc :: pretty $ ABraassignMethid :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_obra
		v.visit n_cbra
		v.visit n_assign
	end
src/pretty.nit:1715,2--1719,4

nitc :: pretty $ ATypeExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit n_type
src/pretty.nit:547,2--53

nitc :: pretty $ AAttrPropdef :: accept_pretty_printer
	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

nitc :: pretty $ ANotExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwnot
		v.adds
		v.visit n_expr
	end
src/pretty.nit:1928,2--1932,4

nitc :: pretty $ AIsaExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_expr
		v.adds
		v.consume "isa"
		v.adds
		v.visit n_type
	end
src/pretty.nit:2033,2--2039,4

nitc :: pretty $ AAttrExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit_recv n_expr
		v.visit n_id
	end
src/pretty.nit:1763,2--1766,4

nitc :: pretty $ AStdClassdef :: accept_pretty_printer
	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

nitc :: pretty $ ALocalPropExternCall :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit n_methid
src/pretty.nit:1086,2--55

nitc :: pretty $ AFullPropExternCall :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_type
		v.visit n_dot
		v.visit n_methid
	end
src/pretty.nit:1078,2--1082,4

nitc :: pretty $ AInitPropExternCall :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do v.visit n_type
src/pretty.nit:1090,2--53

nitc :: pretty $ AUnaryopExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_op
		v.visit n_expr
	end
src/pretty.nit:2059,2--2062,4

nitc :: pretty $ AMethPropdef :: accept_pretty_printer
	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

nitc :: pretty $ AVarAssignExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_id
		v.adds
		v.visit n_assign
		v.adds
		v.visit n_value
	end
src/pretty.nit:1819,2--1825,4

nitc :: pretty $ AStringFormExpr :: accept_pretty_printer
	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

nitc :: pretty $ ASuperstringExpr :: accept_pretty_printer
	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

nitc :: pretty $ AReturnExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwreturn

		if n_expr != null then
			v.adds
			v.visit n_expr
		end
	end
src/pretty.nit:1880,2--1887,4

nitc :: pretty $ ABreakExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwbreak

		if n_expr != null then
			v.adds
			v.visit n_expr
		end

		if n_label != null then
			v.adds
			v.visit n_label
		end
	end
src/pretty.nit:1549,2--1561,4

nitc :: pretty $ AContinueExpr :: accept_pretty_printer
	redef fun accept_pretty_printer(v) do
		v.visit n_kwcontinue

		if n_expr != null then
			v.adds
			v.visit n_expr
		end

		if n_label != null then
			v.adds
			v.visit n_label
		end
	end
src/pretty.nit:1567,2--1579,4

nitc :: pretty $ ADoExpr :: accept_pretty_printer
	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

nitc :: pretty $ AWhileExpr :: accept_pretty_printer
	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

nitc :: pretty $ ALoopExpr :: accept_pretty_printer
	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

nitc :: pretty $ AForExpr :: accept_pretty_printer
	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

nitc :: pretty $ AMainMethPropdef :: accept_pretty_printer
	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