Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / pretty.nit
index f037479..f817b4b 100644 (file)
@@ -121,6 +121,7 @@ class PrettyPrinterVisitor
        # Is the node inlinable and can fit on the line.
        fun can_inline(n: nullable ANode): Bool do
                if n == null then return true
+               if no_inline and n.location.line_start != n.location.line_end then return false
                if n.must_be_inline then return true
                if n.must_be_block then return false
                # check length
@@ -284,6 +285,9 @@ class PrettyPrinterVisitor
 
        # Do we force the deletion of empty lines?
        var skip_empty = false is public writable
+
+       # Disable automatic inlining.
+       var no_inline = false is writable
 end
 
 # Base framework redefs
@@ -693,7 +697,7 @@ redef class AStdClassdef
 
                v.visit n_classkind
                v.adds
-               v.visit n_id
+               v.visit n_qid
 
                if not n_formaldefs.is_empty then
                        v.consume "["
@@ -782,7 +786,7 @@ redef class AType
                        v.adds
                end
 
-               v.visit n_id
+               v.visit n_qid
 
                if not n_types.is_empty then
                        v.consume "["
@@ -941,7 +945,7 @@ redef class ATypePropdef
                super
                v.visit n_kwtype
                v.adds
-               v.visit n_id
+               v.visit n_qid
                v.consume ":"
                v.adds
                v.visit n_type
@@ -1059,7 +1063,7 @@ redef class AExternCalls
                        v.adds
                        v.visit_list n_extern_calls
                else
-                       v.addn
+                       v.forcen
                        v.indent += 1
                        v.addt
                        v.indent -= 1
@@ -1159,7 +1163,7 @@ redef class TExternCodeSegment
                                v.add "`\{"
 
                                if not lines.first.trim.is_empty then
-                                       v.addn
+                                       v.forcen
                                        lines.first.l_trim
                                        v.indent += 1
                                        v.addt
@@ -1236,7 +1240,7 @@ redef class AIfExpr
                        v.adds
                else
                        v.visit n_expr
-                       v.addn
+                       v.forcen
                        v.addt
                end
 
@@ -1515,6 +1519,20 @@ redef class AForExpr
                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
+end
+
+redef class AForGroup
+       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 ", "
@@ -1524,9 +1542,6 @@ redef class AForExpr
                v.consume "in"
                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
 end
 
@@ -1578,11 +1593,11 @@ redef class ACallExpr
                v.visit_recv n_expr
 
                if not n_expr isa AImplicitSelfExpr and not can_inline then
-                       v.addn
+                       v.forcen
                        v.addt
                end
 
-               v.visit n_id
+               v.visit n_qid
 
                if not n_args.n_exprs.is_empty then
                        if is_stmt and n_args.n_exprs.length == 1 then
@@ -1603,7 +1618,7 @@ end
 redef class ACallAssignExpr
        redef fun accept_pretty_printer(v) do
                v.visit_recv n_expr
-               v.visit n_id
+               v.visit n_qid
 
                if not n_args.n_exprs.is_empty then
                        v.consume "("
@@ -1621,7 +1636,7 @@ end
 redef class ACallReassignExpr
        redef fun accept_pretty_printer(v) do
                v.visit_recv n_expr
-               v.visit n_id
+               v.visit n_qid
 
                if not n_args.n_exprs.is_empty then
                        v.consume "("
@@ -1723,17 +1738,17 @@ redef class ANewExpr
                v.adds
                v.visit n_type
 
-               if n_id != null then
+               if n_qid != null then
                        v.consume "."
 
                        if not can_inline then
-                               v.addn
+                               v.forcen
                                v.indent += 1
                                v.addt
                                v.indent -= 1
                        end
 
-                       v.visit n_id
+                       v.visit n_qid
                end
 
                v.visit_args n_args.n_exprs
@@ -1845,7 +1860,7 @@ redef class AAssertExpr
                                else
                                        v.addt
                                        v.visit n_else
-                                       v.addn
+                                       v.forcen
                                        v.indent -= 1
                                        v.addt
                                        v.add "end"
@@ -1973,7 +1988,7 @@ private class ABinOpHelper
                        v.adds
                        v.visit bin_expr2
                else
-                       v.addn
+                       v.forcen
                        v.indent += 1
                        v.addt
                        v.indent -= 1
@@ -2040,16 +2055,9 @@ end
 
 # Syntax
 
-redef class AUplusExpr
-       redef fun accept_pretty_printer(v) do
-               v.consume "+"
-               v.visit n_expr
-       end
-end
-
-redef class AUminusExpr
+redef class AUnaryopExpr
        redef fun accept_pretty_printer(v) do
-               v.consume "-"
+               v.visit n_op
                v.visit n_expr
        end
 end