# NAME
-Pretty print Nit code from Nit source files.
+nitpretty - pretty print Nit code from Nit source files.
-# SYNOPSYS
+# SYNOPSIS
-nitpretty [*options*]...
+nitpretty [*options*]... FILE
# OPTIONS
-`-W`, `--warn`
-: Show more warnings
+`--dir`
+: Working directory (default is '.nitpretty')
-`-w`, `--warning`
-: Show/hide a specific warning
+`-o`, `--output`
+: Output name (default is pretty.nit)
-`-q`, `--quiet`
-: Do not show warnings
+`--diff`
+: Show diff between source and output
-`--stop-on-first-error`
-: Stop on first error
+`--meld`
+: Show diff between source and output using meld
-`--no-color`
-: Do not use color to display errors and warnings
+`--check`
+: Check format of Nit source files
-`--log`
-: Generate various log files
+# SPECIFICATION
-`--log-dir`
-: Directory where to generate log files
+The specification of the pretty printing is described here.
-`-h`, `-?`, `--help`
-: Show Help (This screen)
+* Default indentation level is one `'\t'` character and is increased by one for
+ each indentation level.
+* Default line max-size is 80.
-`--version`
-: Show version and exit
+### COMMENTS
-`--set-dummy-tool`
-: Set toolname and version to DUMMY. Useful for testing
+There is many categories of comments:
-`-v`, `--verbose`
-: Verbose
+`Licence comments` are attached to the top of the file no blank line before,
+one after.
-`--bash-completion`
-: Generate bash_completion file for this program
+~~~nitish
+# This is a licence comment
-`--stub-man`
-: Generate a stub manpage in pandoc markdown format
+# Documentation for module `foo`
+module foo
+~~~
-`--disable-phase`
-: DEBUG: Disable a specific phase; use `list` to get the list.
+`ADoc` are documentation comments attached to a `AModule`, `AClassdef`, `APropdef`.
-`-I`, `--path`
-: Set include path for loaders (may be used more than once)
+They are printed before the definition with a blank line before and no after
+at the same indentation level than the definition.
-`--only-parse`
-: Only proceed to parse step of loaders
+~~~nitish
+# Documentation for module `foo`
+module foo
-`--only-metamodel`
-: Stop after meta-model processing
+# Documentation for class `Bar`
+class Bar
+ # Documentation for method `baz`
+ fun baz do end
+end
+~~~
-`--ignore-visibility`
-: Do not check, and produce errors, on visibility issues.
+`Block comments` are comments composed of one or more line rattached to nothing.
+They are displayed with one blank line before and after at current indent level.
-`--dir`
-: Working directory (default is '.nitpretty')
+~~~nitish
+<blank>
+# block
+# comment
+<blank>
+~~~
-`-o`, `--output`
-: Output name (default is pretty.nit)
+`Attached comments` are comments attached to a production.
+They are printed as this.
-`--diff`
-: Show diff between source and output
+~~~nitish
+fun foo do # attached comment
+end
+~~~
-`--meld`
-: Show diff between source and output using meld
+`nitpretty` automatically remove multiple blanks between comments:
-`--check`
-: Check format of Nit source files
+~~~nitish
+# Licence
+# ...
+<blank>
+# Block comment
+~~~
+
+### INLINING
+
+Productions are automatically inlined when possible.
+
+Conditions:
+
+* The production must be syntactically inlinable
+* The inlined production length is less than `PrettyPrinterVisitor::max-size`
+* The production do not contains any comments
+
+### MODULES
+
+* There is a blank between the module declaration and its imports
+* There is no blank between imports and only one after
+* There is a blank between each extern block definition
+* There is a blank between each class definition
+* There is no blank line at the end of the module
+
+~~~nitish
+# Documentation for module `foo`
+module foo
+
+import a
+import b
+import c
+
+# Documentation for class `Bar`
+class Bar end
+
+class Baz end # not a `ADoc` comment
+~~~
+
+### CLASSES
+
+* There is no blank between the class definition and its super-classes declarations
+* There is no blank between two inlined property definition
+* There is a blank between each block definition
+* There no blank line at the end of the class definition
+
+~~~nitish
+# Documentation for class `Bar`
+class Bar end
+
+class Baz
+ super Bar
+
+ fun a is abstract
+ private fun b do end
+
+ fun c do
+ # ...
+ end
+end
+~~~
+
+Generic types have no space after or before brackets and are separated by a comma and a space:
+
+~~~nitish
+class A[E: Type1, F: Type1] end
+~~~
+
+### BLOCKS
+
+* Inlined productions have no blank lines between them
+* Block productions have a blank before and after
+
+~~~nitish
+var a = 10
+var b = 0
+
+if a > b then
+ is positive
+ print "positive"
+end
+
+print "end"
+~~~
+
+### CALLS AND BINARY OPS
+
+Arguments are always printed separated with a comma and a space:
+
+~~~nitish
+foo(a, b, c)
+~~~
+
+Binary ops are always printed wrapped with spaces:
+
+~~~nitish
+var c = 1 + 2
+~~~
+
+Calls and binary ops can be splitted to fit the `max-size` constraint.
+Breaking priority is given to arguments declaration after the comma.
+
+~~~nitish
+return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
+ "cccccccccccccccccccccccccc")
+~~~
+
+Binary ops can also be broken to fit the `max-size` limit:
+
+~~~nitish
+return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
+ "cccccccccccccccccccccccccc"
+~~~
# SEE ALSO