haskell source code formatter
 
 
Go to file
Lennart Spitzner a0112524aa Split up littests input into multiple files
*.blt instead of just tests.blt

yay for unix-style for ordering the inputs "15-regression.blt"
2017-10-02 20:53:56 +02:00
doc Add another showcase/example 2017-08-03 20:36:46 +02:00
doc-svg-gen Reword docs: Mention that BriDoc trees are DAGs 2017-05-21 13:56:20 +02:00
src/Language/Haskell Support RecordWildCards, Add one-liner layouting for records 2017-10-01 17:24:13 +02:00
src-brittany Merge pull request #59 from d-dorazio/master 2017-10-02 14:13:27 +02:00
src-idemtests Refactor all modules: +Internal; Add public Brittany module 2017-05-22 21:25:08 +02:00
src-libinterfacetests Refactor exposed function (now parsePrintModule) 2017-06-03 18:23:03 +02:00
src-literatetests Split up littests input into multiple files 2017-10-02 20:53:56 +02:00
src-unittests Add sub-config-alternative default to lib interface 2017-07-04 23:26:13 +02:00
srcinc Clean up prelude.inc 2017-08-13 00:42:10 +02:00
.gitignore Add dist-newstyle .gitignore 2017-07-28 18:03:21 +02:00
.travis.yml Adapt travis script to improve build times 2017-09-29 21:42:39 +02:00
ChangeLog.md Add changelog entry for 0.8.0.3 2017-09-26 23:24:00 +02:00
LICENSE Add license (AGPLv3) 2017-06-03 18:23:03 +02:00
README.md Update README.md (ghc versions) 2017-09-26 23:45:56 +02:00
Setup.hs Squash previous history 2016-07-30 15:22:07 +02:00
brittany-sample.gif Add sample gif to README.md 2016-08-12 15:01:15 +02:00
brittany.cabal Split up littests input into multiple files 2017-10-02 20:53:56 +02:00
stack.yaml Update stack.yaml (butcher-1.1.0.2) 2017-09-26 23:45:56 +02:00

README.md

brittany Hackage version Stackage version Build Status

haskell source code formatter

Output sample

(see more examples and comparisons)

This project's goals roughly are to:

  • Always retain the semantics of the source being transformed;
  • Be idempotent (this also directly ensures that only valid haskell is produced);
  • Support the full GHC-haskell syntax including syntactic extensions (but excluding -XCPP which is too hard);
  • Retain newlines and comments unmodified;
  • Be clever about using the available horizontal space while not overflowing it if it cannot be avoided;
  • Be clever about aligning things horizontally (this can be turned off completely however);
  • Have linear complexity in the size of the input.

In theory, the core algorithm inside brittany reaches these goals. It is rather clever about making use of horizontal space while still being linear in the size of the input (although the constant factor is not small). See these examples of clever layouting.

But brittany is not finished yet, and there are some open issues that yet require fixing:

  • only type-signatures and function/value bindings are processed; other module elements (data-decls, classes, instances, imports/exports etc.) are not transformed in any way; this extends to e.g. bindings inside class instance definitions - they won't be touched (yet).
  • By using ghc-exactprint as the parser, brittany supports full GHC including extensions, but some of the less common syntactic elements (even of 2010 haskell) are not handled.
  • There are some known issues regarding handling of in-source comments. There are cases where comments are not copied to the output (this will be detected and the user will get an error); there are other cases where comments are moved slightly; there are also cases where comments result in wonky newline insertion (although this should be a purely aesthetic issue.)
  • There is an open performance issue on large inputs (due to an accidentally quadratic sub-algorithm); noticable for inputs with >1k loc. (fixed in 0.8.0.3)

Other usage notes

  • Supports GHC versions 8.0.* and 8.2.*.
  • config (file) documentation is lacking.
  • some config values can not be configured via commandline yet.
  • uses/creates user config file in ~/.brittany/config.yaml; also reads brittany.yaml in current dir if present.

Installation

  • via cabal "old-build"

    # optionally:
    # mkdir brittany
    # cd brittany
    # cabal sandbox init
    cabal install brittany --bindir=$HOME/.cabal/bin # -w $PATH_TO_GHC_8_0
    
  • via cabal new-build

    cabal unpack brittany
    cd brittany-0.8.0.2
    # cabal new-configure -w $PATH_TO_GHC_8_0
    cabal new-build exe:brittany
    # and it should be safe to just copy the executable, e.g.
    cp `./find dist-newstyle/build/ -type f -name brittany` $HOME/.cabal/bin/
    
  • via stack

    git clone https://github.com/lspitzner/brittany.git
    cd brittany
    stack install
    

Usage

  • Currently one mode of operation: Transform a single module. By default read from stdin and written to stdout, but commandline arguments allow to read/write from/to files.

  • For stdin/stdout usage it makes sense to enable certain syntactic extensions by default, i.e. to add something like this to your ~/.brittany/config.yaml (execute brittany once to create default):

    conf_forward:
      options_ghc:
      - -XLambdaCase
      - -XMultiWayIf
      - -XGADTs
      - -XPatternGuards
      - -XViewPatterns
      - -XRecursiveDo
      - -XTupleSections
      - -XExplicitForAll
      - -XImplicitParams
      - -XQuasiQuotes
      - -XTemplateHaskell
      - -XBangPatterns
    

Implementation/High-level Documentation

See the documentation index

License

Copyright (C) 2016-2017 Lennart Spitzner

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.