ormolu/data/examples
mrkkrp 96390b2405 Fix idempotence bug due to wandering comments
Previously, if an operator had preceding comments attached to its second
argument, they would end up printed right after the operator:

  a
    + -- b comment
      b

On second run however, the comment would be interpreted as attached to ‘(+)’
and the result would be:

  a
    + b -- b comment

Breaking the idempotence guarantees.

The solution that this commit implements includes several steps:

* Introduce the concept of “dirty line”. A line is dirty if it has something
  on it that can have a comment attached to it.

* ‘txt’ is supposed to output fixed bits of syntax that cannot have comments
  attached to them (at least in Ormolu's model).

* ‘atom’ on the other hand outputs things that mark the current line dirty.

* When we're to print preceding comments for the second argument we check if
  the current line is dirty. If it is, we output an extra newline to prevent
  the first comment from changing “hosts”.

* Now there is another problem with trailing whitespace after the operator
  in that case. We solve that by making spaces a bit “lazy”. When the ‘space’
  combinator is used (which is the recommeneded way to separate different
  constructs now) it just guarantees that the next thing we'll output on the
  same line will be separated from previous output by a single space.
  So, using ‘space’ twice results in single space in output still. This has
  the extra benefit of simplifying all the logic that made sure that we have
  only single space and not 0 or 2 spaces when spaces are inserted
  conditionally and independently.
2019-08-27 17:32:11 +02:00
..
declaration Fix idempotence bug due to wandering comments 2019-08-27 17:32:11 +02:00
import Change parens style and how separated lists of items are printed 2019-08-04 13:32:06 +02:00
module-header Tweak formatting of warning pragmas 2019-08-09 11:00:06 +02:00
other Try to contain comments inside enclosing constructs 2019-08-16 16:11:33 +02:00