else
abort
end
- assert current_token.location <= token.location
+ if current_token.location > token.location then return
while current_token != token do visit current_token
end
visit current_token
end
- while current_token isa TEol do skip
+ while current_token isa TEol do visit(current_token)
end
# The template under construction.
consume "."
end
end
+
+ # Do we break string literals that are too long?
+ var break_strings = false is public writable
+
+ # Do we force `do` to be on the same line as the method signature?
+ var inline_do = false is public writable
end
# Base framework redefs
end
redef fun was_inline do
- return first_token.location.line_start == last_token.location.line_end
+ return start_token.location.line_start == last_token.location.line_end
end
end
redef class AAnnotation
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
if not n_args.is_empty then
if n_opar == null then
#
# Were annotations printed inline? If so, we need to print the block differently.
fun visit_block(v: PrettyPrinterVisitor, n_block: nullable AExpr, annot_inline: Bool) do
+ var can_inline = v.can_inline(n_block)
if n_block == null then return
- while not v.current_token isa TKwdo do v.skip
if n_annotations != null and not annot_inline then
v.addn
v.addt
- else
- v.adds
end
+ if v.inline_do then
+ while not v.current_token isa TKwdo do v.skip
+ end
+ var token = v.current_token
+ var do_inline = true
+ loop
+ if token isa TEol then
+ v.skip
+ if not v.can_inline(n_block) then
+ v.addn
+ v.addt
+ do_inline = false
+ end
+ end
+ token = v.current_token
+ if token isa TKwdo then break
+ end
+ if annot_inline and do_inline then v.adds
v.consume "do"
- if v.can_inline(n_block) then
+ if v.can_inline(n_block) and do_inline then
v.adds
if n_block isa ABlockExpr then
redef class AStringFormExpr
redef fun accept_pretty_printer(v) do
- var can_inline = v.can_inline(self)
-
- if can_inline then
+ 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
redef class ASuperstringExpr
redef fun accept_pretty_printer(v) do
- for n_expr in n_exprs do v.visit n_expr
+ 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
redef fun must_be_inline do