mirror of
https://github.com/google/ormolu.git
synced 2024-08-15 19:10:29 +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
|
We set for the following goals (mostly taken from
|
||||||
[brittany](https://github.com/lspitzner/brittany)):
|
[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;
|
* Make reasonable use of screen space;
|
||||||
* Use linear space and computation time on the size of the input;
|
* Use linear space and computation time on the size of the input;
|
||||||
* Preserve comments;
|
* Preserve comments;
|
||||||
@ -140,8 +140,10 @@ impossible to guess what they'll be called on.
|
|||||||
|
|
||||||
### CPP
|
### CPP
|
||||||
|
|
||||||
Formatting a module which uses CPP directives won't be supported. Instead,
|
We allow CPP directives in the input, but we forgo the goal to preserve the
|
||||||
we hope for a solution to replace CPP to do conditional compilation.
|
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:
|
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
|
At the time of this writing, formatting this program with Hindent
|
||||||
produces the same output we would get if the CPP directives were
|
or Ormolu produces the same output we would get if the CPP directives
|
||||||
considered comments:
|
were considered comments:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ hindent --version
|
$ ormolu --version
|
||||||
hindent 5.2.7
|
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
|
$ cat test.hs
|
||||||
{-# LANGUAGE CPP #-}
|
{-# 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
|
extension or mechanism to do conditional compilation, all tools
|
||||||
will benefit from it.
|
will benefit from it.
|
||||||
|
|
||||||
Therefore, CPP won't be supported. If the CPP extension
|
|
||||||
is enabled, we should signal an error right away.
|
|
||||||
|
|
||||||
### Printing
|
### Printing
|
||||||
|
|
||||||
Just pretty-printing code (following the approach of Hindent) seems sane. It
|
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
|
* CPP support is experimental. CPP is virtually impossible to handle
|
||||||
correctly, so we process them as a sort of unchangeable snippets. This
|
correctly, so we process them as a sort of unchangeable snippets. This
|
||||||
works only in simple cases when CPP conditionals are self-contained. Use
|
works only in simple cases when CPP conditionals surround top-level
|
||||||
Ormolu with CPP at your own risk.
|
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
|
* Input modules should be parsable by Haddock, which is a bit stricter
|
||||||
criterion than just being valid Haskell modules.
|
criterion than just being valid Haskell modules.
|
||||||
* Various minor idempotence issues, most of them are related to comments.
|
* 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
|
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
|
[contributing]: https://github.com/tweag/ormolu/blob/master/CONTRIBUTING.md
|
||||||
[license]: https://github.com/tweag/ormolu/blob/master/LICENSE.md
|
[license]: https://github.com/tweag/ormolu/blob/master/LICENSE.md
|
||||||
[haskell-src-exts]: https://hackage.haskell.org/package/haskell-src-exts
|
[haskell-src-exts]: https://hackage.haskell.org/package/haskell-src-exts
|
||||||
|
Loading…
Reference in New Issue
Block a user