Commit Graph

136 Commits

Author SHA1 Message Date
Utku Demir
159e5e7761 Use new operator style in types & declarations
```
a
  + b
```

instead of

```
a +
  b
2019-08-16 16:15:28 +02:00
Utku Demir
f86155a8ea Try to contain comments inside enclosing constructs
Attach the comment if the next element is not a sibling. I think this is
quite often what we want, since if we put a comment inside a construct, we
prefer it to stay inside the same element.
2019-08-16 16:11:33 +02:00
Utku Demir
58f81876e9 Hang record constructor fields 2019-08-16 16:08:17 +02:00
Utku Demir
625f23959c Implement implicit parameter bindings 2019-08-16 15:57:20 +02:00
Utku Demir
16f2c644a7 Implement handling of semicolons 2019-08-16 15:41:40 +02:00
Utku Demir
c3d69d5853 Print multiline comments without changing the contents
Changing the relative position of the closing brace can cause whitespace
changes.
2019-08-16 15:41:26 +02:00
Utku Demir
b3f6e1b4f6 Correctly format when adding annotations to types 2019-08-14 21:35:35 +02:00
Utku Demir
f55021d89b Fix printing of the rewrite rule names 2019-08-14 21:34:05 +02:00
Utku Demir
a392aef71e Fix the issue with promoted containers with promoted elements 2019-08-14 21:31:50 +02:00
Utku Demir
57373e536d Fix formatting of infix type synonyms using ‘p_infixDefHelper’ 2019-08-14 21:30:43 +02:00
Utku Demir
acc77002e4 Support inline specs inside specialize pragmas 2019-08-14 21:24:04 +02:00
Utku Demir
0cf6d654eb Fix TH quoting of operators 2019-08-14 21:23:21 +02:00
mrkkrp
e21e4ef119 Fix mis-formatting of per-argument comments in certain cases 2019-08-13 20:59:22 +02:00
mrkkrp
825171a16d Group deprecation declarations with data types as well 2019-08-11 21:41:23 +02:00
Utku Demir
b6c29bdf12 Handle OPTIONS_GHC and OPTIONS_HADDOCK pragmas
This change adds an ad-hoc parser for module pragmas to handle
OPTIONS_* pragmas. I did not want to use an existing tokenizer,
because I felt like tokenizing and pretty printing the GHC options
are more prone to error without providing much benefit.
2019-08-11 16:04:42 +02:00
Utku Demir
be6d09d148 Workaround GHC tokenizer bug while extracting LANGUAGE pragmas 2019-08-09 11:24:11 +02:00
Utku Demir
c2b32da3b5 Tweak formatting of warning pragmas 2019-08-09 11:00:06 +02:00
mrkkrp
93271b2551 Make sure no comments are swallowed at the end 2019-08-08 20:20:17 +02:00
Utku Demir
a0aa410741 Fix printing of TH brackets
The issue was simply indenting the closing `|]` one more level. However
there were a few more issues around them, which led me to a slightly
bigger refactor.

main reason is that, all `p_*Decl` functions used to print a trailing
newline. This makes sense for top-level constructs, however it was making
printing something like `[d|data Foo = Foo|]` impossible.

In this commit, I removed trailing newlines from individual printers
and gave that responsibility to `p_hsDecls`, and inserted an additional
trailing newline when printing modules.

While doing that, I noticed a few bugs/inconsistencies, and I had to
fix them in the process:

* Warning pragmas used to not print a trailing newline, so they were
always attached to the next expression. I made it more like the other
pragmas, where we attach it to a neighbour function if the name matches,
otherwise we separate it with a newline.
* We used to print single line GADT's and single line `do` notations
using multiple lines, which breaks idempotency. I tweak them to prefer
single line layout if possible (sometimes it is not possible because
of the semicolon syntax).
2019-08-08 11:30:20 +02:00
Utku Demir
e2a6305bd3 Change the way operators are formatted 2019-08-07 20:50:30 +02:00
Teodoro Freund
5955c514ee Fix backticks and parens in multiline function declarations
Function id obtained through pattern matching on ‘FunBind’ should not be
used to print the actual equations because the different ‘RdrNames’ used in
the equations may have different “decorations” (such as backticks and
paretheses) associated with them. It is necessary to use per-equation names
obtained from ‘m_ctxt’ of ‘Match’.
2019-08-07 19:14:59 +02:00
mrkkrp
094e70a2eb Avoid failing when comments get before an operator
This puts out the fire, but I'm not fully content with the solution. I also
do not understand why it fails in the original issue but succeeds for e.g.:

  foo = do
    1
    +
    2
2019-08-05 22:25:38 +02:00
mrkkrp
8fdc9739f0 Fine-tune placement of lambdas after operators 2019-08-05 21:25:34 +02:00
mrkkrp
8870acd41f
Replace weird whitespace characters by normal spaces
I'm just curios of their origin. If I'm not mistaken they were introduced by
@yumiova.
2019-08-05 21:01:52 +02:00
Basile Henry
09e2a538ef Add printer for ‘HsSpliceTy’ 2019-08-05 19:46:47 +02:00
mrkkrp
f86e01ea3b Avoid crashing on unboxed string literals 2019-08-04 23:27:31 +02:00
Mauricio Fierro
bdb22b96ac Fix record pattern synonyms 2019-08-04 22:41:48 +02:00
gabriele.lana
be53b3e504 Format unboxed sum pattern 2019-08-04 21:47:52 +02:00
mrkkrp
e344f61d33 Fix some inconsistency in indentation 2019-08-04 16:50:38 +02:00
mrkkrp
85de7ce38c Add support for the CONLIKE modifier in inlining pragmas 2019-08-04 13:54:08 +02:00
mrkkrp
85d5f78b4b Change parens style and how separated lists of items are printed
Goals:

* Make the set of combinators clearer and smaller.
* Solve a number of issues, such as those about parse failures related to
  patterns.
* Solve the bug from #244.

The idea is very simple, we stop doing this

  ( foo
  , bar
  )

and start doing this

( foo,
  bar
  )

* We switch to trailing commas which solves the indentation issues for
  patterns automatically.
* The new general ‘sep’ combinator finally is clear enough, and all the old
  zoo of ‘velt’ and ‘velt'’ and ‘sepWith’, etc. which was confusing and
  overlapping goes away.
2019-08-04 13:32:06 +02:00
Mitchell Rosen
180df38a71 Fix mixing names with double dot in export lists 2019-07-29 23:14:31 +02:00
Mitchell Rosen
81b291929e Don't separate pattern signature from pattern (fixes #192) 2019-07-29 22:28:28 +02:00
mrkkrp
004c8d0256 Adjust when we put parentheses around TH-quoted names 2019-07-29 22:27:06 +02:00
mrkkrp
d61b9101ca Always put parens around kind signatures 2019-07-21 22:43:55 +02:00
sphaso
116a5a81df Insert space before promoted types where necessary 2019-07-21 21:34:45 +02:00
mrkkrp
46a1c221ab
Also add parentheses around TH-quoted qualified operators 2019-07-21 12:36:30 +02:00
mrkkrp
560c498688 Handle inline comments before let correctly 2019-07-21 12:25:39 +02:00
mrkkrp
de1b33788d Fix parentheses around TH-quoted operators 2019-07-21 12:14:32 +02:00
mrkkrp
ab4885ff0f Preserve empty where clause 2019-07-21 00:30:24 +02:00
sphaso
174a0847d4 Keep comma on multiple GADT declaration 2019-07-20 22:31:54 +02:00
gabriele.lana
8d52d87d72 Preserve operators promotion (single quote)
Fixes #222
2019-07-20 22:07:47 +02:00
sphaso
0065a9baf6 Add space after minus for ‘NegApp’ 2019-07-20 21:53:45 +02:00
waddlaw
68bbc647f7 Always surround the class to derive with parentheses 2019-07-20 21:34:50 +02:00
Daniel Krueger
2cae331d1b Insert space before double dot of arithmetic sequence
This style is arguably ugly, but solves the issue when the type signatures
mess with the double dot. Will do for now.
2019-07-20 20:42:41 +02:00
Basile Henry
b2f49a7693 Support single line where clauses 2019-07-13 19:57:10 +02:00
Basile Henry
0baa898f30 Add tests for let/where interaction #177 2019-07-13 19:57:10 +02:00
Vladislav Zavialov
fd4fa7f33e Comma-separated SPECIALIZE types 2019-07-13 19:56:59 +02:00
Vladislav Zavialov
984e4b674f Keep FunBind strictness 2019-07-13 19:38:46 +02:00
Vladislav Zavialov
b03f989f36 Bang patterns and splices in lambdas 2019-07-13 17:45:52 +02:00