mirror of
https://github.com/tweag/ormolu.git
synced 2024-09-11 21:27:46 +03:00
Update design notes for CPP.
This commit is contained in:
parent
fc64eada5c
commit
5bffeffa05
22
DESIGN.md
22
DESIGN.md
@ -24,7 +24,7 @@ It also includes recommendations for future implementers.
|
||||
|
||||
We set for the following goals (mostly taken from
|
||||
[brittany](https://github.com/lspitzner/brittany)):
|
||||
* Preserve the meaning of the formatted functions;
|
||||
* Preserve the meaning of the formatted functions when no CPP is used;
|
||||
* Make reasonable use of screen space;
|
||||
* Use linear space and computation time on the size of the input;
|
||||
* Preserve comments;
|
||||
@ -140,8 +140,10 @@ impossible to guess what they'll be called on.
|
||||
|
||||
### CPP
|
||||
|
||||
Formatting a module which uses CPP directives won't be supported. Instead,
|
||||
we hope for a solution to replace CPP to do conditional compilation.
|
||||
We allow CPP directives in the input, but we forgo the goal to preserve the
|
||||
meaning of the formatted functions in that case.
|
||||
Instead of supporting CPP better, we hope for a solution to replace CPP to
|
||||
do conditional compilation.
|
||||
|
||||
There are the following challenges when formatting a module with CPP:
|
||||
|
||||
@ -180,14 +182,15 @@ True
|
||||
```
|
||||
|
||||
At the time of this writing, formatting this program with Hindent
|
||||
produces the same output we would get if the CPP directives were
|
||||
considered comments:
|
||||
or Ormolu produces the same output we would get if the CPP directives
|
||||
were considered comments:
|
||||
|
||||
```
|
||||
$ hindent --version
|
||||
hindent 5.2.7
|
||||
$ ormolu --version
|
||||
ormolu 0.0.5.0 HEAD fc64eada5c4da7a5b07d2872e253671b48aec115
|
||||
using ghc-lib-parser 8.10.1.20200412
|
||||
|
||||
$ hindent test.hs
|
||||
$ ormolu --mode inplace test.hs
|
||||
|
||||
$ cat test.hs
|
||||
{-# LANGUAGE CPP #-}
|
||||
@ -227,9 +230,6 @@ to parse Haskell modules. If CPP is replaced with some language
|
||||
extension or mechanism to do conditional compilation, all tools
|
||||
will benefit from it.
|
||||
|
||||
Therefore, CPP won't be supported. If the CPP extension
|
||||
is enabled, we should signal an error right away.
|
||||
|
||||
### Printing
|
||||
|
||||
Just pretty-printing code (following the approach of Hindent) seems sane. It
|
||||
|
@ -116,8 +116,9 @@ independent top-level definitions.
|
||||
|
||||
* CPP support is experimental. CPP is virtually impossible to handle
|
||||
correctly, so we process them as a sort of unchangeable snippets. This
|
||||
works only in simple cases when CPP conditionals are self-contained. Use
|
||||
Ormolu with CPP at your own risk.
|
||||
works only in simple cases when CPP conditionals surround top-level
|
||||
declarations. See the [CPP][design-cpp] section in the design notes for
|
||||
a discussion of the dangers.
|
||||
* Input modules should be parsable by Haddock, which is a bit stricter
|
||||
criterion than just being valid Haskell modules.
|
||||
* Various minor idempotence issues, most of them are related to comments.
|
||||
@ -154,7 +155,7 @@ See [LICENSE.md][license].
|
||||
|
||||
Copyright © 2018–present Tweag I/O
|
||||
|
||||
[design]: https://github.com/tweag/ormolu/blob/master/DESIGN.md#cpp
|
||||
[design-cpp]: https://github.com/tweag/ormolu/blob/master/DESIGN.md#cpp
|
||||
[contributing]: https://github.com/tweag/ormolu/blob/master/CONTRIBUTING.md
|
||||
[license]: https://github.com/tweag/ormolu/blob/master/LICENSE.md
|
||||
[haskell-src-exts]: https://hackage.haskell.org/package/haskell-src-exts
|
||||
|
Loading…
Reference in New Issue
Block a user