nitpretty: does not skip empty lines anymore
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 13 Jan 2015 16:55:23 +0000 (17:55 +0100)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 13 Jan 2015 16:55:23 +0000 (17:55 +0100)
But we let the user chose with --skip-empty

Fixes #1057

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

41 files changed:
src/nitpretty.nit
src/pretty.nit
tests/nitpretty.args
tests/sav/fixme/nitpretty_args48.res [new file with mode: 0644]
tests/sav/fixme/nitpretty_args58.res [new file with mode: 0644]
tests/sav/nitpretty_args21.res
tests/sav/nitpretty_args28.res
tests/sav/nitpretty_args29.res
tests/sav/nitpretty_args30.res
tests/sav/nitpretty_args31.res
tests/sav/nitpretty_args32.res [new file with mode: 0644]
tests/sav/nitpretty_args33.res [new file with mode: 0644]
tests/sav/nitpretty_args34.res [new file with mode: 0644]
tests/sav/nitpretty_args35.res [new file with mode: 0644]
tests/sav/nitpretty_args36.res [new file with mode: 0644]
tests/sav/nitpretty_args37.res [new file with mode: 0644]
tests/sav/nitpretty_args38.res [new file with mode: 0644]
tests/sav/nitpretty_args39.res [new file with mode: 0644]
tests/sav/nitpretty_args40.res [new file with mode: 0644]
tests/sav/nitpretty_args41.res [new file with mode: 0644]
tests/sav/nitpretty_args42.res [new file with mode: 0644]
tests/sav/nitpretty_args43.res [new file with mode: 0644]
tests/sav/nitpretty_args44.res [new file with mode: 0644]
tests/sav/nitpretty_args45.res [new file with mode: 0644]
tests/sav/nitpretty_args46.res [new file with mode: 0644]
tests/sav/nitpretty_args47.res [new file with mode: 0644]
tests/sav/nitpretty_args48.res [new file with mode: 0644]
tests/sav/nitpretty_args49.res [new file with mode: 0644]
tests/sav/nitpretty_args50.res [new file with mode: 0644]
tests/sav/nitpretty_args51.res [new file with mode: 0644]
tests/sav/nitpretty_args52.res [new file with mode: 0644]
tests/sav/nitpretty_args53.res [new file with mode: 0644]
tests/sav/nitpretty_args54.res [new file with mode: 0644]
tests/sav/nitpretty_args55.res [new file with mode: 0644]
tests/sav/nitpretty_args56.res [new file with mode: 0644]
tests/sav/nitpretty_args57.res [new file with mode: 0644]
tests/sav/nitpretty_args58.res [new file with mode: 0644]
tests/sav/nitpretty_args59.res [new file with mode: 0644]
tests/sav/nitpretty_args60.res [new file with mode: 0644]
tests/sav/nitpretty_args61.res [new file with mode: 0644]
tests/sav/nitpretty_args62.res [new file with mode: 0644]

index 545eb58..1d7641d 100644 (file)
@@ -39,6 +39,13 @@ redef class ToolContext
        var opt_inline_do = new OptionBool("Force do keyword on the same line as the method signature",
                "--inline-do")
 
+       # Force formatting on empty lines.
+       #
+       # By default empty lines are kept as they were typed in the file.
+       # When enabling this option, `nitpretty` will decide where to break lines
+       # and will put empty lines to separate properties and code blocks.
+       var opt_skip_empty = new OptionBool("Force formatting of empty lines", "--skip-empty")
+
        # Check formatting instead of pretty printing.
        #
        # This option create a tempory pretty printed file then check if
@@ -63,6 +70,7 @@ var opts = toolcontext.option_context
 opts.add_option(toolcontext.opt_dir, toolcontext.opt_output)
 opts.add_option(toolcontext.opt_diff, toolcontext.opt_meld, toolcontext.opt_check)
 opts.add_option(toolcontext.opt_break_str, toolcontext.opt_inline_do)
+opts.add_option(toolcontext.opt_skip_empty)
 
 toolcontext.tooldescription = "Usage: nitpretty [OPTION]... <file.nit>\n" +
        "Pretty print Nit code from Nit source files."
@@ -95,6 +103,9 @@ end
 if toolcontext.opt_inline_do.value then
        v.inline_do = true
 end
+if toolcontext.opt_skip_empty.value then
+       v.skip_empty = true
+end
 
 for mmodule in mmodules do
        if not mbuilder.mmodule2nmodule.has_key(mmodule) then
index bc556ad..2d08571 100644 (file)
@@ -79,7 +79,7 @@ class PrettyPrinterVisitor
                current_token = nmodule.location.file.first_token
                visit nmodule
                catch_up nmodule.location.file.last_token
-               tpl.add "\n"
+               if skip_empty then tpl.add "\n"
                return tpl.as(not null)
        end
 
@@ -223,6 +223,14 @@ class PrettyPrinterVisitor
                if current_length == 0 and last_line_is_blank then return
                previous_length = current_length
                current_length = 0
+               if skip_empty then wait_addn += 1
+       end
+
+       # Perform `addn` even if not `skip_empty`.
+       fun forcen do
+               if current_length == 0 and last_line_is_blank then return
+               previous_length = current_length
+               current_length = 0
                wait_addn += 1
        end
 
@@ -249,6 +257,9 @@ class PrettyPrinterVisitor
 
        # Do we force `do` to be on the same line as the method signature?
        var inline_do = false is public writable
+
+       # Do we force the deletion of empty lines?
+       var skip_empty = false is public writable
 end
 
 # Base framework redefs
@@ -261,7 +272,7 @@ redef class ANodes[E]
                        if e != first then
                                if not e_can_inline then
                                        v.add ","
-                                       v.addn
+                                       v.forcen
                                        v.indent += 1
                                        v.addt
                                        v.indent -= 1
@@ -315,6 +326,17 @@ redef class Token
        redef fun was_inline do return true
 end
 
+redef class TEol
+       redef fun accept_pretty_printer(v) do
+               if v.skip_empty then
+                       super
+               else
+                       v.add text
+                       v.current_token = next_token
+               end
+       end
+end
+
 redef class Prod
        redef fun accept_pretty_printer(v) do v.visit first_token
 
@@ -362,13 +384,13 @@ redef class TComment
                if is_adoc then
                        v.addt
                        super
-                       v.addn
+                       v.forcen
                        return
                end
 
                if is_licence then
                        super
-                       v.addn
+                       v.forcen
                        if is_last_in_group then v.addn
                        return
                end
@@ -377,7 +399,7 @@ redef class TComment
                        v.addn
                        v.addt
                        super
-                       v.addn
+                       v.forcen
                        v.addn
                        return
                end
@@ -386,13 +408,14 @@ redef class TComment
                        if next_token isa TComment and is_first_in_group then v.addn
                        v.addt
                        super
-                       v.addn
+                       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
 
        # Is `self` part of an `ADoc`?
@@ -454,13 +477,19 @@ redef class AAnnotations
                                if v.current_token isa TKwend then v.skip
                        end
                else
-                       v.addn
+                       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 v.addn
+                               if n_item != n_items.last then
+                                       if was_inline then
+                                               v.forcen
+                                       else
+                                               v.addn
+                                       end
+                               end
                        end
                        v.indent -= 1
                end
@@ -504,7 +533,7 @@ redef class AModule
                v.visit n_moduledecl
 
                if not n_imports.is_empty then
-                       v.addn
+                       if v.skip_empty then v.addn
 
                        for n_import in n_imports do
                                v.catch_up n_import
@@ -526,7 +555,7 @@ redef class AModule
                end
 
                if not n_classdefs.is_empty then
-                       v.addn
+                       if v.skip_empty then v.addn
 
                        for n_classdef in n_classdefs do
                                v.catch_up n_classdef
@@ -571,7 +600,7 @@ redef class AModuledecl
                end
 
                v.finish_line
-               v.addn
+               if v.skip_empty then v.addn
        end
 end
 
@@ -592,7 +621,7 @@ redef class ANoImport
                v.adds
                v.visit n_kwend
                v.finish_line
-               v.addn
+               if v.skip_empty then v.addn
        end
 end
 
@@ -607,7 +636,7 @@ redef class AStdImport
                v.adds
                v.visit n_name
                v.finish_line
-               v.addn
+               if v.skip_empty then v.addn
        end
 end
 
@@ -619,9 +648,9 @@ redef class AClassdef
                        v.catch_up n_propdef
 
                        if n_propdef.n_doc != null or not v.can_inline(n_propdef) then
-                               if n_propdef != n_propdefs.first then v.addn
+                               if v.skip_empty and n_propdef != n_propdefs.first then v.addn
                                v.visit n_propdef
-                               if n_propdef != n_propdefs.last then v.addn
+                               if v.skip_empty and n_propdef != n_propdefs.last then v.addn
                        else
                                v.visit n_propdef
                        end
@@ -670,7 +699,7 @@ redef class AStdClassdef
                        end
                else
                        v.finish_line
-                       v.addn
+                       if v.skip_empty then v.addn
                        v.indent += 1
 
                        for n_superclass in n_superclasses do
@@ -682,7 +711,7 @@ redef class AStdClassdef
                        end
 
                        if not n_superclasses.is_empty and not n_propdefs.is_empty then
-                               v.addn
+                               if v.skip_empty then v.addn
                        end
 
                        super
@@ -692,7 +721,7 @@ redef class AStdClassdef
 
                v.visit n_kwend
                v.finish_line
-               v.addn
+               if v.skip_empty then v.addn
                assert v.indent == 0
        end
 
@@ -795,10 +824,10 @@ redef class APropdef
        #
        # 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)
+               # var can_inline = v.can_inline(n_block)
                if n_block == null then return
                if n_annotations != null and not annot_inline then
-                       v.addn
+                       v.forcen
                        v.addt
                end
                if v.inline_do then
@@ -810,7 +839,7 @@ redef class APropdef
                        if token isa TEol then
                                v.skip
                                if not v.can_inline(n_block) then
-                                       v.addn
+                                       v.forcen
                                        v.addt
                                        do_inline = false
                                end
@@ -838,7 +867,11 @@ redef class APropdef
                        end
                else
                        v.finish_line
-                       v.addn
+                       if was_inline then
+                               v.forcen
+                       else
+                               v.addn
+                       end
                        v.indent += 1
 
                        if n_block isa ABlockExpr then
@@ -848,7 +881,7 @@ redef class APropdef
                        else
                                v.addt
                                v.visit n_block
-                               v.addn
+                               v.forcen
                        end
 
                        v.indent -= 1
@@ -968,7 +1001,7 @@ end
 redef class AMainMethPropdef
        redef fun accept_pretty_printer(v) do
                v.visit n_block
-               v.addn
+               if v.skip_empty then v.addn
        end
 end
 
@@ -1122,7 +1155,7 @@ redef class TExternCodeSegment
 
                                for line in lines do
                                        v.add line.r_trim
-                                       v.addn
+                                       v.forcen
                                end
 
                                v.addt
@@ -1212,11 +1245,18 @@ redef class AIfExpr
                        else if n_then == null then
                                v.add "end"
                        end
-
                        v.skip_to last_token.last_real_token_in_line
                else
                        v.finish_line
-                       v.addn
+                       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
@@ -1226,7 +1266,11 @@ redef class AIfExpr
                                else
                                        v.addt
                                        v.visit n_then
-                                       v.addn
+                                       if n_then.was_inline then
+                                               v.forcen
+                                       else
+                                               v.addn
+                                       end
                                end
                        end
 
@@ -1245,7 +1289,11 @@ redef class AIfExpr
                                        v.visit n_else
                                else
                                        v.finish_line
-                                       v.addn
+                                       if was_inline then
+                                               v.forcen
+                                       else
+                                               v.addn
+                                       end
                                        v.indent += 1
 
                                        if n_else isa ABlockExpr then
@@ -1254,7 +1302,11 @@ redef class AIfExpr
                                        else
                                                v.addt
                                                v.visit n_else
-                                               v.addn
+                                               if n_else.was_inline then
+                                                       v.forcen
+                                               else
+                                                       v.addn
+                                               end
                                        end
 
                                        if last_token isa TKwend then
@@ -2125,7 +2177,11 @@ redef class AStringFormExpr
 
                                if v.current_length >= v.max_size and i <= text.length - 3 then
                                        v.add "\" +"
-                                       v.addn
+                                       if was_inline then
+                                               v.forcen
+                                       else
+                                               v.addn
+                                       end
                                        v.indent += 1
                                        v.addt
                                        v.indent -= 1
index fa592d3..77c26ea 100644 (file)
@@ -1,3 +1,34 @@
+--skip-empty test_pretty/test_mod1.nit
+--skip-empty test_pretty/test_mod2.nit
+--skip-empty test_pretty/test_mod3.nit
+--skip-empty test_pretty/test_class1.nit
+--skip-empty test_pretty/test_class2.nit
+--skip-empty test_pretty/test_class3.nit
+--skip-empty test_pretty/test_prop1.nit
+--skip-empty test_pretty/test_prop2.nit
+--skip-empty test_pretty/test_prop3.nit
+--skip-empty test_pretty/test_loop1.nit
+--skip-empty test_pretty/test_loop2.nit
+--skip-empty test_pretty/test_loop3.nit
+--skip-empty test_pretty/test_call1.nit
+--skip-empty test_pretty/test_call2.nit
+--skip-empty test_pretty/test_if1.nit
+--skip-empty test_pretty/test_if2.nit
+--skip-empty test_pretty/test_if3.nit
+--skip-empty test_pretty/test_op1.nit
+--skip-empty test_pretty/test_op2.nit
+--skip-empty test_pretty/test_op3.nit
+--skip-empty test_pretty/test_extern1.nit
+--skip-empty test_pretty/test_attr1.nit
+--skip-empty test_pretty/test_attr2.nit
+--skip-empty test_pretty/test_comments1.nit
+--skip-empty test_pretty/test_indent1.nit
+--skip-empty test_pretty/test_prims1.nit
+--skip-empty test_pretty/test_annot1.nit
+--skip-empty --break-strings test_pretty/test_prop1.nit
+--skip-empty --break-strings test_pretty/test_indent1.nit
+--skip-empty --inline-do test_pretty/test_prop1.nit
+--skip-empty --inline-do test_pretty/test_indent1.nit
 test_pretty/test_mod1.nit
 test_pretty/test_mod2.nit
 test_pretty/test_mod3.nit
diff --git a/tests/sav/fixme/nitpretty_args48.res b/tests/sav/fixme/nitpretty_args48.res
new file mode 100644 (file)
index 0000000..c3a432c
--- /dev/null
@@ -0,0 +1,61 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+# 0
+if a == b then # 1
+       # 2
+else # 3
+       # 4
+end # 5
+
+if a == b then print a # printing a
+
+if a == b then
+       print a # printing a
+end
+
+if a == b then print a
+ # end
+
+if a == b then a = b
+
+if a == b then end
+
+if a == b then end
+
+if a != b then a = b
+
+
+if a > b then
+       a = b
+else
+       a = b
+end
+
+if a < b then
+       a = b
+else if a == b then
+       a = b
+end
+
+if a < b then
+       a = b
+else if a == b then
+       a = b
+else
+       a = b
+end
diff --git a/tests/sav/fixme/nitpretty_args58.res b/tests/sav/fixme/nitpretty_args58.res
new file mode 100644 (file)
index 0000000..2e6ac9a
--- /dev/null
@@ -0,0 +1,51 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module test_annot1 is platform("android")
+
+class A
+       fun goo is intern
+
+       # test
+       fun foo is a, b
+       fun bar is a, b do print "1"
+       fun baz is
+               a
+               bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+       do print "2"
+end
+
+class B
+       fun foo is a, b
+
+
+       fun bar is a, b
+ do print "1"
+
+       fun baz is a, b
+ do
+               bar
+               print "2"
+       end
+
+       fun gaz is
+               a
+               bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+
+       do
+               bar
+               print "2"
+       end
+
+end
index 325eddc..7a8fe04 100644 (file)
@@ -84,4 +84,4 @@ end
 
 fun address_is_null: Bool is extern "address_is_null"
 
-fun free `{ free(recv); `}
\ No newline at end of file
+fun free `{ free(recv); `}
index 83c9064..1944090 100644 (file)
@@ -48,4 +48,4 @@ class B
        end
 end
 
-# end
\ No newline at end of file
+# end
index 8f24177..4d75c17 100644 (file)
@@ -124,4 +124,4 @@ var body = """
                </ul>
        </div>
 </body>
-</html>"""
\ No newline at end of file
+</html>"""
index 4820e6d..57f7966 100644 (file)
@@ -45,4 +45,4 @@ class B
        end
 end
 
-# end
\ No newline at end of file
+# end
index 3364250..99d53dd 100644 (file)
@@ -106,4 +106,4 @@ var body = """
                </ul>
        </div>
 </body>
-</html>"""
\ No newline at end of file
+</html>"""
diff --git a/tests/sav/nitpretty_args32.res b/tests/sav/nitpretty_args32.res
new file mode 100644 (file)
index 0000000..f55be8f
--- /dev/null
@@ -0,0 +1,18 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
+# An empty module
+
diff --git a/tests/sav/nitpretty_args33.res b/tests/sav/nitpretty_args33.res
new file mode 100644 (file)
index 0000000..76149a7
--- /dev/null
@@ -0,0 +1,24 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Testing only imports
+
+# Module comment
+module test_mod2 # second comment
+
+import standard::kernel
+#import standard::string
+
+import template # no need for string
+# import standard
\ No newline at end of file
diff --git a/tests/sav/nitpretty_args34.res b/tests/sav/nitpretty_args34.res
new file mode 100644 (file)
index 0000000..6ee57a1
--- /dev/null
@@ -0,0 +1,25 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A simple module
+module test_mod3
+
+# before
+print "Hello World" # comment
+# after
+
+# end
+
+
+
diff --git a/tests/sav/nitpretty_args35.res b/tests/sav/nitpretty_args35.res
new file mode 100644 (file)
index 0000000..ed30bc2
--- /dev/null
@@ -0,0 +1,24 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment 1
+interface A end
+
+abstract class B # comment 2
+end
+
+class C end # comment 3
+
+enum D end # comment 4
+
diff --git a/tests/sav/nitpretty_args36.res b/tests/sav/nitpretty_args36.res
new file mode 100644 (file)
index 0000000..2a61cf1
--- /dev/null
@@ -0,0 +1,25 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module test_class2
+
+
+# comment
+class A end
+
+class B[T] # comment
+end
+
+private class C[U, V: B[A]] end # comment
+
diff --git a/tests/sav/nitpretty_args37.res b/tests/sav/nitpretty_args37.res
new file mode 100644 (file)
index 0000000..feedd55
--- /dev/null
@@ -0,0 +1,39 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment
+class A end
+
+class B[T] # comment
+       # comment
+       super A # comment
+
+
+       super C[A, B[A]]
+       # comment
+end
+
+class C[U, V: B[A]] end # comment
+
+class D super A end # comment
+
+class E
+
+
+
+       super A # comment
+end
+
+# end
+
diff --git a/tests/sav/nitpretty_args38.res b/tests/sav/nitpretty_args38.res
new file mode 100644 (file)
index 0000000..31e90fc
--- /dev/null
@@ -0,0 +1,46 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment 1
+class A
+       type FOO: Discrete
+       private var foo: FOO # comment
+       # comment 2
+       var bar: Int = 10
+end
+
+class B
+       super A
+
+       redef type FOO: Int
+       # comment 3
+       redef fun foo do return bar # comment
+       redef fun bar
+       do
+               return 10 # comment 4
+       end
+       fun baz do return # comment 5
+       protected fun baz2 do end
+       fun other: String do
+               return "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+       end
+
+       fun foo1(arr: Array[String], len: Int, ind: Int): String
+       do
+               return "Hello World!"
+       end
+end
+
+# end
+
diff --git a/tests/sav/nitpretty_args39.res b/tests/sav/nitpretty_args39.res
new file mode 100644 (file)
index 0000000..e48e1da
--- /dev/null
@@ -0,0 +1,32 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       fun foo(a, b: Int): Bool do return true # 1
+
+       fun foo2(a, b: Int): Bool do return true # 2
+
+       fun foo3(a, b: Int): Bool do return true
+
+       fun foo4(a, b: Int): Bool do
+               var res = true # 3
+               return res # 4
+       end
+
+       fun foo5 do end # 5
+       # fun foo6 do end
+end
+
+# end
+
diff --git a/tests/sav/nitpretty_args40.res b/tests/sav/nitpretty_args40.res
new file mode 100644 (file)
index 0000000..59e2e25
--- /dev/null
@@ -0,0 +1,35 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       fun foo(aaaaaaaaaaaaaa,
+               bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: Int): Bool do return true # comment
+
+       fun foo2(a, b: Int): Bool do return true # comment
+
+       fun foo3(a, b: Int): Bool do # comment
+               return true # comment
+       end # comment
+
+       fun foo4(a, b: Int): Bool do # comment
+               var res = true # comment
+               return res # comment
+       end # comment
+
+       fun foo5 do end # comment
+
+       fun foo6(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
+               aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Int) do print 1
+
+end # comment
\ No newline at end of file
diff --git a/tests/sav/nitpretty_args41.res b/tests/sav/nitpretty_args41.res
new file mode 100644 (file)
index 0000000..1be308b
--- /dev/null
@@ -0,0 +1,34 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+while a != b do # comment 1
+       # comment 2
+       var tmp = a
+       a = b
+       b = tmp
+       # comment 3
+end
+
+# comment 4
+while a != b do a = b # comment 5
+
+while a != b do
+       # comment 6
+end # comment 7
+
+# end
+
diff --git a/tests/sav/nitpretty_args42.res b/tests/sav/nitpretty_args42.res
new file mode 100644 (file)
index 0000000..6b49ffa
--- /dev/null
@@ -0,0 +1,47 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 0
+var b = 2
+
+do # comment 1
+       # comment 2
+       var tmp = a
+       a = b
+       b = tmp
+       # comment 3
+end
+
+# comment 4
+do a = b # comment 5
+
+do
+       # comment 6
+end
+
+if a > b then loop print a # test
+
+if a > b then loop print a
+
+
+if a > b then loop print a
+
+
+if a > b then
+       loop
+               # comment 7
+               print a
+       end
+end
+
diff --git a/tests/sav/nitpretty_args43.res b/tests/sav/nitpretty_args43.res
new file mode 100644 (file)
index 0000000..0135aa1
--- /dev/null
@@ -0,0 +1,27 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 0
+
+for i in [1, 2, 3] do # comment 1
+       # comment 2
+       a += i
+end
+
+# comment 4
+for i in [1..3] do a += i # comment 5
+
+for i in [1..3[ do
+       # comment 6
+end
diff --git a/tests/sav/nitpretty_args44.res b/tests/sav/nitpretty_args44.res
new file mode 100644 (file)
index 0000000..2cd014e
--- /dev/null
@@ -0,0 +1,36 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       fun foo do end
+       fun bar(a: Int): Int do return 1
+       fun baz(a, b: Int) do end
+       fun gaz(a: Int, b: Float...) do end
+end
+
+fun top1 do end
+fun top2(a: Int) do end
+
+# comment 1
+var a = new A # comment 2
+a.foo # comment 3
+a.bar 1 # comment 4
+a.baz(1, 2) # comment 5
+top1 # comment 6
+top2 10 # comment 7
+
+print 10 # comment 8
+
+var b = a.bar(1)
+
diff --git a/tests/sav/nitpretty_args45.res b/tests/sav/nitpretty_args45.res
new file mode 100644 (file)
index 0000000..789abdd
--- /dev/null
@@ -0,0 +1,39 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       var attr: Int
+       fun foo1=(i: Int) do end
+       fun foo2=(i, j: Int) do end
+       fun [](a: Int): Int is abstract
+       fun []=(a, b: Int) do end
+end
+
+class B
+       fun [](a, b: Int): Int is abstract
+       fun []=(a, b, c: Int) do end
+end
+
+# comment 1
+var a = new A(10) # comment 2
+
+a.foo1 = 10 # comment 3
+a.foo2(1) = 10 # comment 4
+print a[1] # comment 5
+a[1] = 2 # comment 6
+a[2] += 3 # comment 7
+
+var b = new B
+print b[1, 2]
+b[1, 2] = 10
diff --git a/tests/sav/nitpretty_args46.res b/tests/sav/nitpretty_args46.res
new file mode 100644 (file)
index 0000000..60bf5ef
--- /dev/null
@@ -0,0 +1,50 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+if a == b then a = b
+
+if a != b then
+       a = b
+       a = b
+end
+
+if a > b then
+       b = a
+       a = b
+else
+       a = b
+       a = b
+end
+
+if a < b then
+       a = b
+       a = b
+else if a == b then
+       b = a
+       a = b
+end
+
+if a < b then
+       a = b
+       a = b
+else if a == b then
+       b = b
+       a = b
+else
+       a = b
+       a = b
+end
diff --git a/tests/sav/nitpretty_args47.res b/tests/sav/nitpretty_args47.res
new file mode 100644 (file)
index 0000000..12d8db5
--- /dev/null
@@ -0,0 +1,81 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment
+var a = 1 # comment
+# comment
+var b = 2 # comment
+
+# comment
+if a == b then a = b # comment
+
+# comment
+if a != b then # comment
+       # comment
+       a = b # comment
+       # comment
+       a = b # comment
+       # comment
+end # comment
+
+# comment
+if a > b then # comment
+       # comment
+       b = a # comment
+       # comment
+       a = b # comment
+       # comment
+else # comment
+       # comment
+       a = b # comment
+       # comment
+       a = b # comment
+       # comment
+end # comment
+
+# comment
+if a < b then # comment
+       # comment
+       a = b # comment
+       # comment
+       a = b # comment
+       # comment
+else if a == b then # comment
+       # comment
+       b = a # comment
+       # comment
+       a = b # comment
+       # comment
+end # comment
+
+# comment
+if a < b then # comment
+       # comment
+       a = b # comment
+       # comment
+       a = b # comment
+       # comment
+else if a == b then # comment
+       # comment
+       b = b # comment
+       # comment
+       a = b # comment
+       # comment
+else # comment
+       # comment
+       a = b # comment
+       # comment
+       a = b # comment
+       # comment
+end # comment
\ No newline at end of file
diff --git a/tests/sav/nitpretty_args48.res b/tests/sav/nitpretty_args48.res
new file mode 100644 (file)
index 0000000..bfde8c2
--- /dev/null
@@ -0,0 +1,59 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+# 0
+if a == b then # 1
+       # 2
+else # 3
+       # 4
+end # 5
+
+if a == b then print a # printing a
+
+if a == b then
+       print a # printing a
+end
+
+if a == b then print a # end
+
+if a == b then a = b
+
+if a == b then end
+
+if a == b then end
+
+if a != b then a = b
+
+if a > b then
+       a = b
+else
+       a = b
+end
+
+if a < b then
+       a = b
+else if a == b then
+       a = b
+end
+
+if a < b then
+       a = b
+else if a == b then
+       a = b
+else
+       a = b
+end
diff --git a/tests/sav/nitpretty_args49.res b/tests/sav/nitpretty_args49.res
new file mode 100644 (file)
index 0000000..4fec81e
--- /dev/null
@@ -0,0 +1,21 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a: nullable Int = 1
+var b: nullable Int = a.as(Int)
+var c: nullable Int = a.as(not null)
+
+assert c isa Int
+assert test1: c isa Int
+assert test2: c isa Int else abort
diff --git a/tests/sav/nitpretty_args50.res b/tests/sav/nitpretty_args50.res
new file mode 100644 (file)
index 0000000..c428dcb
--- /dev/null
@@ -0,0 +1,31 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+assert a == 2
+assert not a < 2 # comment 1
+assert a > 2 and b >= 2
+assert b != 2 or a <= 2
+assert b != null # comment 2
+
+# comment 3
+print a + b
+print a - b # comment 4
+print a * b
+print a / b
+print a % b
+
+print -a # comment 5
\ No newline at end of file
diff --git a/tests/sav/nitpretty_args51.res b/tests/sav/nitpretty_args51.res
new file mode 100644 (file)
index 0000000..90425ff
--- /dev/null
@@ -0,0 +1,27 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = 1
+var b = 2
+
+assert not a < 2 and (a == b or a > b) # comment 1
+assert not a < 2 and (a == b or ((a > b) or a <= b))
+assert (a > 2 and b >= 2)
+assert (b >= 2)
+
+# comment 3
+var c = a + (b - a)
+var d = (a - b) + c # comment 4
+var e = (-a) # comment 5
+var f = -(a - c)
diff --git a/tests/sav/nitpretty_args52.res b/tests/sav/nitpretty_args52.res
new file mode 100644 (file)
index 0000000..415c33f
--- /dev/null
@@ -0,0 +1,88 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import end
+intrude import standard::kernel
+private import standard::string
+
+`{`}
+
+`{
+#ifdef truc
+       #undef truc
+#endif
+`}
+
+in "C headers" `{
+       #include <errno.h>
+`}
+
+fun err: Int is extern `{ return 1; `}
+
+fun errno: Int is extern `{
+       return errno;
+`}
+
+fun errnoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: Int is
+       extern `{ return errno; `}
+
+private class A
+       var my_attr = 1234
+
+       fun baz(msg: String) import String.length, String.to_cstring, my_attr, my_attr= `{
+               char *c_msg;
+               int msg_len;
+
+               /* String_to_cstring isa a allback to msg.to_cstring */
+               c_msg = String_to_cstring( msg );
+
+               /* String_length is a callback to msg.length */
+               msg_len = String_length( msg );
+
+               printf( "received msg: %s, of length = %d\n", c_msg, msg_len );
+
+               /* A_my_attr is a callback to the getter of self.my_attr */
+               printf( "old attr %d\n", A_my_attr(recv) );
+
+               if(chose)
+                       truc;
+               else
+                       chose;
+
+               /* A_my_attr is a callback to the setter of self.my_attr= */
+               A_my_attr__assign( recv, msg_len );
+       `}
+end
+
+extern class TimeT `{time_t`}
+       new `{ return time(NULL); `}
+       new from_i(i: Int) `{ return i; `}
+
+       fun update `{ time(&recv); `}
+
+       fun ctime: String import NativeString.to_s_with_copy `{
+               return NativeString_to_s_with_copy( ctime(&recv) );
+       `}
+
+       # Difference in secondes from start (self if the end time)
+       fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+
+       private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]): nullable Int is
+               extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`}
+end
+
+fun address_is_null: Bool is extern "address_is_null"
+
+fun free `{ free(recv); `}
+
diff --git a/tests/sav/nitpretty_args53.res b/tests/sav/nitpretty_args53.res
new file mode 100644 (file)
index 0000000..8152504
--- /dev/null
@@ -0,0 +1,35 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       var a: Int # comment
+       private var b: nullable Int # happy
+       protected var c = 10 # ending
+       var d: Int = 10
+
+
+
+
+
+       # Test test...
+       var e: Int is writable
+       var f: Int is protected writable
+       # Adoc
+       var k: Int = 10 is protected writable
+
+
+
+       # more comments
+end # end
+
diff --git a/tests/sav/nitpretty_args54.res b/tests/sav/nitpretty_args54.res
new file mode 100644 (file)
index 0000000..08a4d49
--- /dev/null
@@ -0,0 +1,24 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class Foo
+       var a: Int
+       private var b: nullable Int
+       protected var c = 10
+       var d: Int = 10
+end
+
+var foo = new Foo(1, 2)
+print foo._a
+foo._a = 10
diff --git a/tests/sav/nitpretty_args55.res b/tests/sav/nitpretty_args55.res
new file mode 100644 (file)
index 0000000..2096847
--- /dev/null
@@ -0,0 +1,98 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# toplevel comment
+
+
+
+
+
+
+# block
+# block
+# block
+
+
+
+
+
+# Adoc1
+class A # ending comments
+
+       super Object
+       # super Int
+
+
+       super String
+       # super Truc
+
+
+
+       # inclass comments
+       # comm
+       #    ented
+       #      blocks
+
+
+
+       # Adoc2
+       fun foo do
+
+               # comment
+
+
+
+               var truc
+
+               # comment
+               # comment
+
+
+
+               # comment
+
+
+               var chose
+
+               # comment
+       end
+
+       # comm
+       #    ented
+       #      blocks
+
+
+       fun bar do end
+
+
+       fun baz do end
+       # comment before end
+
+end # ending comments
+
+# comm
+#    ented
+#      blocks
+
+abstract class B # comment
+end
+
+abstract class C end
+
+abstract class B # comment 2
+
+end
+
+abstract class C end
diff --git a/tests/sav/nitpretty_args56.res b/tests/sav/nitpretty_args56.res
new file mode 100644 (file)
index 0000000..adabdcf
--- /dev/null
@@ -0,0 +1,111 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class Foo
+       fun bar: Bool do return true
+
+       fun foo(other: Foo): Foo
+       do
+               if other.bar then
+                       return other
+               else
+                       return self
+               end
+       end
+
+       fun baz: Int do
+               var nb = 0
+               while nb < 10 do
+                       print nb
+                       nb += 1
+               end # 1
+               return nb
+       end
+
+       fun gaz: Int
+       do
+               if bar then # 3
+                       return 1
+               else
+                       return -1 # 4
+               end
+       end
+end
+
+class Test[E]
+       var heap: ArrayHeap[E]
+
+       init to(comparator: Comparator[E]) do heap = new ArrayHeap[E](comparator)
+
+       init from(comparator: Comparator[E], items: Collection[E]) do
+               heap = new ArrayHeap[E].from(comparator, items.to_a)
+       end
+
+       fun count(k: E): Int do
+               if heap.has(k) then
+                       return 1
+               else
+                       return 0
+               end
+       end
+
+       fun node_at_idx(i: Int, k: E) do
+               while heap != null do
+                       if heap.is_empty or i == k then # FIXME prefilter because the compiler is not smart enought yet
+                               break
+                       end
+               end
+       end
+
+       fun save_those_nodes(nodes: Collection[Object]) do
+               for node in nodes do count(node)
+       end
+end
+
+fun foo do
+       if last_slash > 0 then
+               return substring(last_slash + 1, length)
+       else
+               return null
+       end
+end
+
+print "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis lorem. Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus ipsum placerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed pharetra lacus."
+
+var lorem = "lorem"
+var ipsum = "ipsum" # for fun
+
+print "We also need to handle super strings: {lorem} {ipsum} dolor sit amet, consectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis {lorem}. Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus {ipsum} placerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed pharetra lacus." # ending
+
+var title = "title"
+var links = new Array[String] # why not?
+
+var body = """
+<!DOCTYPE html>
+<head>
+       <meta charset="utf-8">
+       <meta http-equiv="X-UA-Compatible" content="IE=edge">
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+       <title>{{{title}}}</title>
+</head>
+<body>
+       <div class="container">
+               <h1>{{{title}}}</h1>
+               <ul>
+                       <li>{{{links.join("</li>\n\t\t\t<li>")}}}</li>
+               </ul>
+       </div>
+</body>
+</html>"""
+
diff --git a/tests/sav/nitpretty_args57.res b/tests/sav/nitpretty_args57.res
new file mode 100644 (file)
index 0000000..e385838
--- /dev/null
@@ -0,0 +1,48 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# prims
+
+var a = true
+var b = false
+
+var c = 10
+var d = -10
+var e = 1.12
+
+var f = -1.12
+var n = 'a'
+var o = null
+var p = 0x12345678
+
+# strings
+
+var g = "test"
+var h1 = "Hello {g}"
+var h2 = "Hello \"{g}\" Hello"
+var h3 = "Hello {g}"
+var m = """
+bla
+       bla
+
+bla"""
+
+# arrays
+
+var j = [1, 2, 3]
+var k = [1..2[
+var l = [1..2]
+
+
+
diff --git a/tests/sav/nitpretty_args58.res b/tests/sav/nitpretty_args58.res
new file mode 100644 (file)
index 0000000..edc3f3f
--- /dev/null
@@ -0,0 +1,48 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module test_annot1 is platform("android")
+
+class A
+       fun goo is intern
+
+       # test
+       fun foo is a, b
+       fun bar is a, b do print "1"
+       fun baz is
+               a
+               bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb do print "2"
+end
+
+class B
+       fun foo is a, b
+
+
+       fun bar is a, b do print "1"
+
+       fun baz is a, b
+       do
+               bar
+               print "2"
+       end
+
+       fun gaz is
+               a
+               bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+       do
+               bar
+               print "2"
+       end
+
+end
diff --git a/tests/sav/nitpretty_args59.res b/tests/sav/nitpretty_args59.res
new file mode 100644 (file)
index 0000000..dadc656
--- /dev/null
@@ -0,0 +1,47 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment 1
+class A
+       type FOO: Discrete
+       private var foo: FOO # comment
+       # comment 2
+       var bar: Int = 10
+end
+
+class B
+       super A
+
+       redef type FOO: Int
+       # comment 3
+       redef fun foo do return bar # comment
+       redef fun bar
+       do
+               return 10 # comment 4
+       end
+       fun baz do return # comment 5
+       protected fun baz2 do end
+       fun other: String do
+               return "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                       "aaaaaaaaaaaaaaaaaaaaaaaaaa"
+       end
+
+       fun foo1(arr: Array[String], len: Int, ind: Int): String
+       do
+               return "Hello World!"
+       end
+end
+
+# end
+
diff --git a/tests/sav/nitpretty_args60.res b/tests/sav/nitpretty_args60.res
new file mode 100644 (file)
index 0000000..0fd4ac4
--- /dev/null
@@ -0,0 +1,127 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class Foo
+       fun bar: Bool do return true
+
+       fun foo(other: Foo): Foo
+       do
+               if other.bar then
+                       return other
+               else
+                       return self
+               end
+       end
+
+       fun baz: Int do
+               var nb = 0
+               while nb < 10 do
+                       print nb
+                       nb += 1
+               end # 1
+               return nb
+       end
+
+       fun gaz: Int
+       do
+               if bar then # 3
+                       return 1
+               else
+                       return -1 # 4
+               end
+       end
+end
+
+class Test[E]
+       var heap: ArrayHeap[E]
+
+       init to(comparator: Comparator[E]) do heap = new ArrayHeap[E](comparator)
+
+       init from(comparator: Comparator[E], items: Collection[E]) do
+               heap = new ArrayHeap[E].from(comparator, items.to_a)
+       end
+
+       fun count(k: E): Int do
+               if heap.has(k) then
+                       return 1
+               else
+                       return 0
+               end
+       end
+
+       fun node_at_idx(i: Int, k: E) do
+               while heap != null do
+                       if heap.is_empty or i == k then # FIXME prefilter because the compiler is not smart enought yet
+                               break
+                       end
+               end
+       end
+
+       fun save_those_nodes(nodes: Collection[Object]) do
+               for node in nodes do count(node)
+       end
+end
+
+fun foo do
+       if last_slash > 0 then
+               return substring(last_slash + 1, length)
+       else
+               return null
+       end
+end
+
+print "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tincidun" +
+       "t sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit a" +
+       "met lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus" +
+       " eu orci congue iaculis eu quis lorem. Ut et blandit erat. Cras fermentum pell" +
+       "entesque ante, ut dapibus ipsum placerat sit amet. Vivamus pharetra, sem vitae" +
+       " consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae" +
+       " lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas" +
+       " turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed phar" +
+       "etra lacus."
+
+var lorem = "lorem"
+var ipsum = "ipsum" # for fun
+
+print "We also need to handle super strings: {lorem} {ipsum} dolor sit amet, con" +
+       "sectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius a" +
+       "t non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisi" +
+       "s neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis {lorem}" +
+       ". Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus {ipsum} pla" +
+       "cerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus pl" +
+       "acerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum " +
+       "augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pell" +
+       "entesque vitae arcu justo. Aliquam sed pharetra lacus." # ending
+
+var title = "title"
+var links = new Array[String] # why not?
+
+var body = """
+<!DOCTYPE html>
+<head>
+       <meta charset="utf-8">
+       <meta http-equiv="X-UA-Compatible" content="IE=edge">
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+       <title>{{{title}}}</title>
+</head>
+<body>
+       <div class="container">
+               <h1>{{{title}}}</h1>
+               <ul>
+                       <li>{{{links.join("</li>\n\t\t\t<li>")}}}</li>
+               </ul>
+       </div>
+</body>
+</html>"""
+
diff --git a/tests/sav/nitpretty_args61.res b/tests/sav/nitpretty_args61.res
new file mode 100644 (file)
index 0000000..6b5b168
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# comment 1
+class A
+       type FOO: Discrete
+       private var foo: FOO # comment
+       # comment 2
+       var bar: Int = 10
+end
+
+class B
+       super A
+
+       redef type FOO: Int
+       # comment 3
+       redef fun foo do return bar # comment
+       redef fun bar do
+               return 10 # comment 4
+       end
+       fun baz do return # comment 5
+       protected fun baz2 do end
+       fun other: String do
+               return "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+       end
+
+       fun foo1(arr: Array[String], len: Int, ind: Int): String do
+               return "Hello World!"
+       end
+end
+
+# end
+
diff --git a/tests/sav/nitpretty_args62.res b/tests/sav/nitpretty_args62.res
new file mode 100644 (file)
index 0000000..329aa03
--- /dev/null
@@ -0,0 +1,109 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class Foo
+       fun bar: Bool do return true
+
+       fun foo(other: Foo): Foo do
+               if other.bar then
+                       return other
+               else
+                       return self
+               end
+       end
+
+       fun baz: Int do
+               var nb = 0
+               while nb < 10 do
+                       print nb
+                       nb += 1
+               end # 1
+               return nb
+       end
+
+       fun gaz: Int do
+               if bar then # 3
+                       return 1
+               else
+                       return -1 # 4
+               end
+       end
+end
+
+class Test[E]
+       var heap: ArrayHeap[E]
+
+       init to(comparator: Comparator[E]) do heap = new ArrayHeap[E](comparator)
+
+       init from(comparator: Comparator[E], items: Collection[E]) do
+               heap = new ArrayHeap[E].from(comparator, items.to_a)
+       end
+
+       fun count(k: E): Int do
+               if heap.has(k) then
+                       return 1
+               else
+                       return 0
+               end
+       end
+
+       fun node_at_idx(i: Int, k: E) do
+               while heap != null do
+                       if heap.is_empty or i == k then # FIXME prefilter because the compiler is not smart enought yet
+                               break
+                       end
+               end
+       end
+
+       fun save_those_nodes(nodes: Collection[Object]) do
+               for node in nodes do count(node)
+       end
+end
+
+fun foo do
+       if last_slash > 0 then
+               return substring(last_slash + 1, length)
+       else
+               return null
+       end
+end
+
+print "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis lorem. Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus ipsum placerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed pharetra lacus."
+
+var lorem = "lorem"
+var ipsum = "ipsum" # for fun
+
+print "We also need to handle super strings: {lorem} {ipsum} dolor sit amet, consectetur adipiscing elit. Aliquam tincidunt sapien et velit fringilla varius at non eros. Nunc ut ultricies metus, sit amet lacinia felis. Donec in facilisis neque, non laoreet nibh. Etiam nec purus eu orci congue iaculis eu quis {lorem}. Ut et blandit erat. Cras fermentum pellentesque ante, ut dapibus {ipsum} placerat sit amet. Vivamus pharetra, sem vitae consequat venenatis, diam risus placerat est, sed hendrerit purus justo vitae lectus. In id quam mattis, rutrum augue eu, vehicula ipsum. Nulla nec egestas turpis, nec ullamcorper odio. Pellentesque vitae arcu justo. Aliquam sed pharetra lacus." # ending
+
+var title = "title"
+var links = new Array[String] # why not?
+
+var body = """
+<!DOCTYPE html>
+<head>
+       <meta charset="utf-8">
+       <meta http-equiv="X-UA-Compatible" content="IE=edge">
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+       <title>{{{title}}}</title>
+</head>
+<body>
+       <div class="container">
+               <h1>{{{title}}}</h1>
+               <ul>
+                       <li>{{{links.join("</li>\n\t\t\t<li>")}}}</li>
+               </ul>
+       </div>
+</body>
+</html>"""
+